Not sure you want to do it like this, but just in case, you can use the filter nav_menu_css_class
:
function my_special_nav_class( $classes, $item ) {
if ( is_single() && $item->title == 'Blog' ) {
$classes[] = 'special-class';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'my_special_nav_class', 10, 2 );
You’ll find more example here
Related Posts:
- Mega Menu Walker
- start_lvl Ignored in Custom walker_nav_menu
- Walker class: Problems with understanding how walk() method can be called without error
- Run a filter when a walker runs
- Can’t extend some core classes
- Trouble creating conditional PHP for nav menu items with children for custom Walker
- Automatically adding new post categories to menu
- Custom Walker_Nav_Menu issue with variables on PHP 7.3
- Trying to store submenu items to render out after main menu
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- New walker for walker_nav_menu to change inside container data
- Add login hyperlink to secondary navigation menu
- How to display different submenus?
- Extend Menu Walker Output
- Nav Walker that shows only children and siblings of top level parent menu item
- Adding markup to sub menu based on class
- Difference between “Walker_Nav_menu” and “walker”
- Add parent menu item in sub-menu in custom nav_walker
- Add the “.current-menu-item” class to tag?
- Custom Links in Walker Class
- I am extending Walker_Nav_Menu: How can I get the number of children elements of the current item?
- Adding first / last CSS classes to menus
- Hide main div if wp_nav_menu is empty
- wp_delete_auto_drafts() deletes links in menus
- Check if a menu is empty?
- how to put the logo in the center of other items in the navigation bar
- How to remove a metabox from menu editor page?
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- How to create different menu’s for not logged in visitors and for logged in members?
- Can we have a php “page” without a WordPress “page”?
- How to add active class to custom menu using while loop and wp_list_pages
- How to place login logout link on menu that redirects users back to current page?
- wp_delete_auto_drafts() deletes links in menus
- Unusable menus and “Illegal widget setting ID: nav_menu_item[]” error
- Logout and redirect using the WP Menu
- Creating new menu item
- Programmatically create menu with custom link
- Custom Loop through category menu to include sub categories
- wp nav menu: add attributes to menu items [duplicate]
- Have CSS Class Added with `is_page()` WP function
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Change Navigation Bar based on logged in or not
- create a select input with menus created on a custom options page
- Change list item content in menu navigation to add a child element with specific class
- How can I Add a variable PHP in the Menu Nav
- Where to place PHP code that inserts (or doesn’t insert) menu item?
- Adding an Avatar to the Top Nav Bar
- Add data attribute to each li in menu
- Remove metabox from WordPress menu editor page?
- How to add an arrow to menu items has submenus
- wp_nav_menu returns menu list in ascending order. How can I arrange the menu same as dashboard menu
- Unique icons next to each WordPress menu item
- Child page menu in sidebar
- Title Case WordPress Menu Items
- get_the_title() gets printed out twice
- Two menus show up
- Show About and Contact Us page when they’re clicked in the top menu.
- Add data-id attribute to child page links
- wp_nav_menu not working correctly in my underscores theme
- Notice: Trying to get property of non-object
- How to use wp_nav_menu to create custom dropdown menu?
- Get css class of menu item in custom menu structure
- Nav-Menu not showing up
- Show login greeting above sub-menu links?
- Why can’t I add a custom image in my navigation?
- How to tell if a user has gone in and created a menu
- Menu not styling. New menus functionality giving me a headache
- Hard-coding a shortcode as the last menu item in primary navigation?
- Add class to ul and li in wp_na
- how to changes mobile menu toggle breakpoint in WordPress
- How to display already created menus via php?
- Providin exception to WordPress wp_nav_menu Custom CSS Classes
- dynamic php menu with hidden sub-categories only showing when the category name is clicked
- How to put 2 php codes in functions.php without site crashing
- Menu not updating for logged in users after redirect
- wp_get_nav_menu_items() with ACF
- How to switch between two primary menus (programatically0
- How to let mobile navigation menu close when link is clicked?
- Used a code to revoke some dashboard menus for my contributors but for some reason it’s revoked me access to the editor [closed]
- How to give custom roles the capability to edit one Menu instead of every Menu
- Primary navigation menu with timed items from custom post type
- Add element after navigation element title don’t works like I expect
- How to create a sub-page of sub-page?
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Widget Logic – display on page and all child
- How to list categories by page id in wordpress
- Adding button to wordpress menu
- wp_nav_menu doesn’t work in a duplicate server
- How I can add div to menu?
- Add extra markup to WP menus
- Using ‘array’ method in wp_nav_menu causes it to disappear
- How to get the count for each taxonomy term
- WP_Nav Highlight Parent Issue
- How to change the menu color
- if is_home(), change class of menu-item-225 of wp_nav_menu
- Change order that the menu is generated with wp_list_pages
- How do I modify the with wp_nav_menu()
- Make a permalink to the most recent blog post
- Inserting a shortcode into a genesis menu?
- Custom nav with bootstrap dropdown