Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using this code to display my menu:

<?php 

$menu_args = array(
     'container'       => '', 
     'menu_class'      => '', 
     'menu_id'         => 'main-menu',
     );

wp_nav_menu($menu_args ); 

?>

It works totally fine, but I don't know how to get rid of all these classes attached to every li in my menu?

Example:

<li id="menu-item-227" class="menu-item menu-item-type-post_type current-menu-item page_item page-item-77 current_page_item menu-item-227">

It's pretty long, isn't it?

I don't need classes and even IDs here at all, since my menu has one already.

Any ideas?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

you can use nav_menu_css_class filter hook to remove the classes:

add_filter('nav_menu_css_class' , 'my_nav_menu_remove_class' , 10 , 2);
function my_nav_menu_remove_class($classes, $item){
    $my_class = array('menu-item-class');
    return $my_class;
}
share|improve this answer
    
+1, that's a nice trick! But still, every li has an ID and in addiction your code doesn't remove "class" at all, just allows me to set one. When $my_class array is empty it still produces "class=" "" :( –  Wordpressor Mar 25 '11 at 18:41
    
You can always return an empty array rather than an array with an empty string in it. Even easier, you can just do this: add_filter('nav_menu_css_class' , '__return_empty_array'); –  goldenapples Mar 25 '11 at 23:42

nav_menu_css_class only works on custom menus, for standard menus you'll also need to apply the function to the page_css_class hook as well.

And at the risk of seeming obnoxious, I also have a small plug-in that does exactly what you're talking about: http://aarontgrogg.com/2011/09/28/wordpress-plug-in-navigation-menu-ids-classes/

It even gives you the ability to pick-and-choose which, if any, of the WP class you want to keep (for example, all the class that reflect the page you're currently viewing can be handy to have for your CSS needs).

Cheers, Atg

share|improve this answer

AFAIK, you'll have to write your own custom walker to remove those pesky classes and IDs. I can see about writing something out for you (it's on my own to-do list), but this might help you get started: http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.