• ryancolins

    (@ryancolins)


    I’m having trouble getting a filter on nav_menu-css_class to work and I can’t figure out why. I’m using the this example on the reference page for wp nav menu.

    <?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;
    }
    ?>

    For testing purposes, I changed it to this to try to get it to work at all:

    add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
    function special_nav_class($classes, $item){
                 $classes[] = "special-class";
    
         return $classes;
    }

    I would think with out the condition statement, it would add the “special-class” to every nav item, but its not. It doesn’t look like its getting called at all? Can anyone help me figure out why?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘nav_menu_css_class filter not working’ is closed to new replies.