Skip to main content

Remove every class and ID from the wp_nav_menu

  • Remove class and Id attribute from list item in wordpress menu

    --PATH wp-content\themes\<yourTheme>\functions.php
    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')) : '';
    }
    

    Using this code snippet you can remove every class and ID attribute from the list of wordpress menu. You can remove all class and ID attribute with their values from <li> list item in menu list. It will show only the passed value to the current menu item. wp_nav_menu() function displays a navigation menu which allows you to navigate to most parts of your website.

  • Back to code snippet queries related wordpress