0

It could look like a possible duplicate, but I have tried a plenty of solutions, and none of them has worked. The very last any basic one:

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

And my nav call:

wp_nav_menu( array( 'theme_location' => 'header-menu', 'menu_class' => 'navigationList', 'container' => 'ul') );

Ul gets the correct class. However, the li items still have page_item classes and nothing else. Why? I have spent 30 minutes on this issue and still haven't found why. Thanks a lot in advance!

  • 1
    Your code works for me, where did you place your fiter ? – Benoti Nov 8 '16 at 18:30
  • @Aniket Sahrawat, kybernaut.cz's code is correct. The index would only be needed if the intention was to change a specific item in the array which is not the case here. – Dave Romsey Nov 8 '16 at 18:49
  • To remove all $classes just add unset($classes); in the callback function. – Benoti Nov 8 '16 at 19:51
2

You code is working for me with (and without) some modifications on your code, to place in functions.php :

add_filter( 'nav_menu_css_class', 'menu_item_classes', 10, 4 );

function menu_item_classes( $classes, $item, $args, $depth ) {

    unset($classes);

    $classes[] = 'current-menu-ancestor';

    return $classes;
}

If it's still not working, verify that your are working on the right theme_location id in wp_nav_menu().

Hope it helps !

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.