Skip to content

Instantly share code, notes, and snippets.

@chriskoelle
Created January 8, 2014 03:30
Show Gist options
  • Save chriskoelle/8311326 to your computer and use it in GitHub Desktop.
Save chriskoelle/8311326 to your computer and use it in GitHub Desktop.
Wordpress Cleanup wp_nav_menu Classes
// Cleanup some of the extra menu item classes added to wp_nav_menu
function nh_allowed_menu_item_classes($classes, $item) {
// Get custom classes added from within the menus admin page
$new_classes = (array) get_post_meta( $item->ID, '_menu_item_classes', true );
// Consolidate the assorted "current..." classes
$current_classes = preg_grep('/current/', $classes);
if(!empty($current_classes)) $new_classes[] = 'current';
return $new_classes;
}
add_filter('nav_menu_css_class', 'nh_allowed_menu_item_classes', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment