try this code in your functions file.
function add_class_to_nav_items($nav_items, $args) {
if ( $args['theme_location'] == 'MY_NAV_THEME_LOCATION' ) { // IMPORTANT: replace MY_NAV_THEME_LOCATION with the location of your menu
foreach ($nav_items as &$nav_item) {
$nav_item->classes[] = 'custon-class-name';
}
}
return $nav_items;
}
add_filter( 'wp_nav_menu_objects', 'add_class_to_nav_items', 11 );
Related Posts:
- How to add wechat (weixin) link to navigation menu?
- Admin only menu/page
- Add custom menu item using wp_nav_menu_items filter
- Does Extending Multiple Nav_Menu_Walkers Allow Nested Menus?
- wp_nav_menu remove class and id from li
- Add separator to admin submenu
- On which hook should I be calling register_nav_menu(s)?
- Removing link ” from ” menu for some “links” without JS
- Using filters to change href of nav menu page link
- Menu is not visible in appearance
- One site, 2 distinct sections: two different top nav menus?
- Links open only on new tab or window
- Make Theme automatically choose default nav menu
- How can I disable parent menu item links?
- How to get current page menu item name instead of full menu item list
- Organizing by super-categories (or nested categories)?
- Nav menu items disappearing (but not immediately)
- wp_nav_menu custom walker – child items
- Adding different classes to anchor in navigation menu
- wp_nav_menu doesn’t generate parent/ancestor classes
- Add static item to wp_nav_menu
- How to get wordpress nav menu outside of wordpress system?
- Pending Custom Link in Menu
- Add nav menu CSS class to body
- Change HTML structure for custom menu in sidebar
- Using Shortcodes in WP-Menus in WP 3.1 (via nav_menu_objects)?
- Force PDF download from custom menu?
- Page-Linking Structure
- Current menu item
- remove everything from wp_nav_menu
- Best way to customise wp_nav_menu [duplicate]
- Image as a link using wp_nav_menu()
- Link that refers to a menu item with dynamically generated URL
- Fragment URL in navigation item without a custom link
- Link to Homepage in Menu
- How to add custom classes to more than one separate menu’s a link in wordpress?
- How do I separate link levels in a custom menu walker?
- SlideDeck 2, make back-end visible for admins only
- Separator for custom nav menu
- How do you link to a place in another page without any styling issues?
- Custom Links menu items include in Search Results
- Menu custom link not working for external site
- Help with walker for nav
- Create custom page and add it in nav menu by code
- Using my WordPress menu on another platform
- Links do not open from click, only in new tab [closed]
- Remove a menu sub-item
- How to add html attributes to the “ul” html tag with “wp_nav_menu” function?
- Using _s theme, menu changes do not affect header menu
- Limit User Iinterface for Admin?
- Make pages visible to only logged in members
- Get custom classes in WordPress Navigation Menu
- Replace the slug of parent pages with # [closed]
- How to change the link on the logo at the menu?
- Creating Menu Links in a Custom Theme
- The cart, checkout, and shop links not getting removed
- How do I create a root link in wordpress to a PDF file?
- Position a hard-coded menu item
- How to undo the last changes to a custom menu?
- URL links consistent with menus?
- Filter to hook into menu items and add a custom attribute
- I can’t add more pages to menu – menu delete pages
- Responsive menu on genesis theme [closed]
- Opening Menu link in another tab
- How to add class to anchor using wp_nav_menu
- Simple form to add custom links to menu?
- How to open a lightbox form from a navigation menu item
- Main menu navigation links and new pages
- custom menu widget where menu title is a link
- Hide custom menu when when no menu selected
- How to show pages in menu without link
- Problem with links once in portfolio item
- How to create a link-less parent (top level) menu item that doesn’t use an anchor tag
- Menu links URL with PHP GET method
- Classes CSS (Optional) – how do I reference this in php?
- Why does WordPress convert absolute URLs to relative URLs for menu items?
- Parent link need to go first child submenu
- Adding images to anchors in the list created and fetched with wp_nav_menu
- Links in new menu don’t work
- How to make menu output links absolute
- how to display wordpress navbar with top menu outside wordpress system
- change link of menu particular tab
- Menu Structure with Links failure to update
- Top menu link anchor href value change after online server?
- Creating and populating custom nav menu (menu-item-position not working)
- Show content of subdomain from specific menu-item?
- wp_nav_menu in 3.7 add name class nav navbar-nav
- Navigational error
- How do I add a link to the menu that has a charector (?) in it?
- Remove link from Page name in navigation bar
- custom walker to add iconfont to wp_nav_menu
- Change menu item order
- Menu System: Custom Links
- Unsual behaviour of navigation Menus
- How to centre menu items on horizontal nav bar? (e.g. make margins equal) [closed]
- Wrapping my ‘s with
- Displaying list of random links using wp_nav_menu
- WordPress removes URL parameters from menu elements when saving the menu
- how to add permalink/slug to wordpress custom link menu item
- After WordPress 4.8 upgrade, wp_nav_menu() string search / replace not working