Skip to content

Instantly share code, notes, and snippets.

@certainlyakey
Created December 29, 2016 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save certainlyakey/44379b32b8e75c7cd3b3f50027b4155a to your computer and use it in GitHub Desktop.
Save certainlyakey/44379b32b8e75c7cd3b3f50027b4155a to your computer and use it in GitHub Desktop.
Remove all classes in a Wordpress-based menus, except those given
// Remove all classes in a Wordpress-based menus, except those given
function css_attributes_filter($var) {
return is_array($var) ? array_intersect($var, array('current-menu-item','current_page_item','current-page-ancestor','current-menu-ancestor','current-menu-parent')) : '';
}
add_filter('nav_menu_css_class', 'css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'css_attributes_filter', 100, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment