The three lines below will remove all IDs and classes from menu items, including classes for the current item:
add_filter('nav_menu_css_class', '__return_empty_array');
add_filter('nav_menu_item_id', '__return_empty_string');
add_filter('page_css_class', '__return_empty_array');
The current item can still be targeted using the aria-current attribute:
.menu li a[aria-current="page"] {
color: red;
}
Documentation
- WordPress Developer Resources - Functions - __return_empty_array
- WordPress Developer Resources - Functions - __return_empty_string
- WordPress Developer Resources - Hooks - nav_menu_css_class
- WordPress Developer Resources - Hooks - nav_menu_item_id
- WordPress Developer Resources - Hooks - page_css_class