Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Thanks to Rarst's clever answer, I'm succesfully using these bits to remove the classes from the custom menu markup...

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

function discard_menu_classes($classes, $item) {
    return (array)get_post_meta( $item->ID, '_menu_item_classes', true );
    }

However, I do need the current-menu-item and current-menu-parent classes when I'm viewing a current page element or a child of a current-menu-item.

Is it possible to add these without all the extra classes?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Sure, you can filter out all the classes but the ones you want.

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

function discard_menu_classes($classes, $item) {
    $classes = array_filter( 
        $classes, 
        create_function( '$class', 
                 'return in_array( $class, 
                      array( "current-menu-item", "current-menu-parent" ) );' )
        );
    return array_merge(
        $classes,
        (array)get_post_meta( $item->ID, '_menu_item_classes', true )
        );
    }
share|improve this answer
    
I'd write out code (not that much of it for this) rather than creating function. –  Rarst Oct 6 '11 at 17:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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