wordpress snippets last updated   : April 22, 2014
we now have 631 snippets

Remove every class and id from the wp_nav_menu

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will remove nearly every class and id from the wp_nav_menu except for the current-menu-item class. This is a great little snippet that will make your wp_nav_menu a little cleaner enjoy.

snippet :  PHPcopy
add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
function my_css_attributes_filter($var) {
  return is_array($var) ? array_intersect($var, array('current-menu-item')) : '';
}
source →
  • http://electronicsnewsline.com/ Electronics News

    Thanks for sharing this coding, will try at once, nice idea…..

    • http://wpsnipp.com Kevin Chard

      Cool glad to help.

      • Jeremy Smith

        How would you go about making one of the li elements with an ID? Like I mean you’d have say a ul list of 6 links for example and one of them (the first one for arguments sake) would be oh I don’t know with the id ‘login’?

        Like so:

        Login
        Carry on with the rest

        Be interesting to know

  • William

    should i put it under any functions? or i just paste the code on my functions.php?~~

jqsnipp.com | we just launched jquery snippets website