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');
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
- developer.wordpress.org/reference/functions/__return_empty_array
- developer.wordpress.org/reference/functions/__return_empty_string
- developer.wordpress.org/reference/hooks/nav_menu_css_class
- developer.wordpress.org/reference/hooks/nav_menu_item_id
- developer.wordpress.org/reference/hooks/page_css_class