1

I'm calling wp_nav_menu programmatically on a class and I'd like to be able to set the field that will be shown as the current-menu-item but I don't see an argument for that.

It seems like I may be able to use nav_menu_css_class?

0

Adding Conditional Classes to Menu Items

This example would let you add a custom class to a menu item based on the condition you specify. Don't forget to change the condition.

<?php
add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
function special_nav_class($classes, $item){
     if(is_single() && $item->title == "Blog"){ //Notice you can change the conditional from is_single() and $item->title
             $classes[] = "special-class";
     }
     return $classes;
}
?>

Also take a look at How to Add a Custom Class to a WordPress Menu Item.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.