Skip to content

111 Recipes

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

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');

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

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

Documentation