WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 3 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( 
        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 )
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


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.