Example of WordPress default CSS class output:
<li id="menu-item-55" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-55">
<li class="page_item page-item-37">
The menu and pages list item come with various own li class
and id
.
How to remove them in functions.php
file for the menu and for the pages list?
You should be able to remove them by hooking into a couple of filters and returning empty arrays or strings rather than new classes or ids:
If you wanted to keep particular classes you could do something like this:
this is an addition on top of Richard answer.
in case you want to change the current-menu-item class to something else.
Here is a fix that I’ve come up with. It removes all the id’s and classes from the wp_nav_menu, but allows you to come up with your own “approved” list of classes and/or id’s. It also changes the lengthy “current-menu-item” to “active”. If you prefer to keep the the default WordPress CSS styles, just delete that section of the code. For the sake of keeping this post minimal, here are the links to the pastebin with the code:
http://pastebin.com/W16cxDfY – for your functions.php file
http://pastebin.com/CGx4aprf – for your template, wherever the menu goes
simply
add_filter('nav_menu_item_id', '__return_false');
for menu item idBest way to remove li is: Tested and Verified
If you just want to remove all the list classes and id’s, add this to functions.php
An addition to Richard’s answer:
We need to clean up the empty classes left behind:
My solution: