Created
July 27, 2012 04:51
-
-
Save peterwilsoncc/3186233 to your computer and use it in GitHub Desktop.
Kill them useless menu classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pwcc_filter_nav_menu_css_class($classes, $item, $args) { | |
unset($classes); | |
$classes = array(); | |
if (trim($item->classes[0]) != '') { | |
$classes[] = $item->classes[0]; | |
} | |
$classes[] = 'menu-item'; | |
if ($item->current OR $item->current_item_ancestor OR $item->current_item_parent) { | |
$classes[] = 'menu-item-on'; | |
} | |
if ( $item->current_item_ancestor OR $item->current_item_parent) { | |
$classes[] = 'menu-item-up'; | |
} | |
if ($item->current) { | |
$classes[] = 'menu-item-is'; | |
} | |
return array_unique( $classes ); | |
} | |
add_filter( 'nav_menu_css_class', 'pwcc_filter_nav_menu_css_class', 10, 3); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a simpler approach to do the same thing.