This is to reduce rather than to remove all CSS classes that WordPress adds to the nav menu ( wp_menu_nav ). This function removes all classes except ‘current-menu-item’. So, this leaves in ‘current-menu-item’.
For all list of all the menu classes the are inserted into wp_nav_menu by default, see Menu_Item_CSS_Classes.
/* * Removes all wp_menu_nav classes EXCEPT 'current-menu-item' */ function smartest_nav_class_filter( $var ) { return is_array($var) ? array_intersect($var, array('current-menu-item')) : ''; } add_filter('nav_menu_css_class', 'smartest_nav_class_filter', 100, 1);
Note: This really isn’t necessary for the purpose I was using it for. I could have altered my CSS to not depend on the .last-item
selector. But I find this is cleaner.
Questions and Comments are Welcome