i want to disable default menu class, bellow code is disable menu class completely.

add_theme_support( 'menus' );
add_filter('nav_menu_css_class', 'my_css_attributes_filter', 10, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
function my_css_attributes_filter($var) {
    return is_array($var) ? array_intersect($var, array('current-menu-item', 'current-menu-ancestor')) :

but now issue is when even i add custom class in menu

enter image description here

example navcon that class not coming. i understand a bit it because of add_filter('nav_menu_css_class', 'my_css_attributes_filter', 10, 1); so is there any way just disable all defualt class but if have custom class then it will add

my trample code is <?php wp_nav_menu( array('menu' => 'mainmenu','items_wrap'=>'%3$s', 'container' => false)); ?>

  • 1
    Dump the value of $var inside your callback. Then edit your question and show the output.
    – kaiser
    Apr 8, 2016 at 3:13
  • thanks for reply. not really understand what to do.
    – pagol
    Apr 8, 2016 at 3:41
  • Add a var_dump( $var ); in your my_css_attributes_filter function and add the output to the question.
    – kaiser
    Apr 8, 2016 at 3:47
  • thank you. i changed function my_css_attributes_filter($var) { to function var_dump( $var ) { but it give me Fatal error. also i replace all my_css_attributes_filter to var_dump( $var ); but it not work.
    – pagol
    Apr 8, 2016 at 3:59
  • Sorry, but this is going nowhere this way… The only thing that can help you is a copy/paste solution which you won't find here. You are better off when you search and pay a developer to help you solve your problem.
    – kaiser
    Apr 8, 2016 at 4:12

1 Answer 1


i got a answer from another thread.. which is bellow

    add_filter('nav_menu_css_class', 'discard_menu_classes', 10, 2);

function discard_menu_classes($classes, $item) {
    $classes = array_filter( 
        create_function( '$class', 
                 'return in_array( $class, 
                      array( "current-menu-item", "current-menu-parent" ) );' )
    return array_merge(
        (array)get_post_meta( $item->ID, '_menu_item_classes', true )

ref : http://wordpress.stackexchange.com/questions/30417/removing-all-classes-from-nav-menu-except-current-menu-item-and-current-menu-par

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.