How to remove class attributes from custom menu markup?

Just playing around with adding “custom menu” support to my theme. I’m super excited about it.

HOWEVER,

Read More

Check this out >

<ul id="menu-my-main-menu" class="menu">
  <li id="menu-item-12" 
      class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-12">
      <a href="http://localhost/bizsite">Home</a>
  </li>
</ul>

Worst case of “class-itus” I think I’ve ever seen. Is this something “I” did unintentionally or is this the default?

How can I control or remove the class attribs on these menus?

Related posts

Leave a Reply

1 comment

  1. You can use the nav_menu_css_class filter to remove the classes that you want from your menu-item.

    See the example below, to remove ALL the CSS classes that are appended to you menu items:

    add_filter('nav_menu_css_class','remove_nav_menu_classes');
    function remove_nav_menu_classes($classes) {
        return array(); 
    }
    

    Do a print_r($classes) if you want to know which classes are active in your menu.