Hi, if you want to remove and clean unnecessary classes and IDs from WordPress site being added while using custom navigation menus? So then here’s a some function code to remove them:
As you can see example from the above image, The screenshot taken of the page source all those long classes and IDs. and after cleaning up the wp_nav_menu(), Here is the image below shows after cleaner menu.
INSTRUCTION:
Step 1: First login to your WP Dashboard with your current username and Password, Then go to the directly into “Appereance” and “Theme Editor” and find the functions.php file and click on that functions.php.
Step 2: Now paste the below code into your “functions.php” this should remove all the nasty classes and IDs from your wp_nav_menu
add_filter(‘nav_menu_css_class’, ‘my_css_attributes_filter’, 100, 1);
add_filter(‘nav_menu_item_id’, ‘my_css_attributes_filter’, 100, 1);
add_filter(‘page_css_class’, ‘my_css_attributes_filter’, 100, 1);
function my_css_attributes_filter($var) {
return is_array($var) ? array_intersect($var, array(‘current-menu-item’)) : ”;
}
Finally click on “Update File” and save your work, Now you can go your public website and view the source code press by “CTRL+U” from keyword maybe there has removed WP Menu classes and IDs.
In the end
I hope you have found this article helpful. Let us me your opinion or questions if any through the comment form in below or use this form to ask your question.