Skip to content

111 Recipes

How to remove all CSS classes and IDs from WordPress menu items

Published ·UPD ·In Recipes
add_filter('nav_menu_item_id', '__return_empty_string');
add_filter('nav_menu_css_class', '__return_empty_array');
add_filter('page_css_class', '__return_empty_array');

The three lines above will remove all IDs and classes from menu items, including classes for the current item. The current item can still be targeted using the aria-current attribute:

.menu li a[aria-current="page"] {
  color: red;
}

Documentation