• [ Moderator note: moved to How-to and Troubleshooting. ]

    It would be reeeaaally reeaally good if we could have an option to simply skip echoing id and classes in each list when using wp_nav_menu.
    So instead of having
    <li id="menu-item-156" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-156">
    we can have good old simple <li>
    I find those classes completely unnecessary in every project I have and they only add meaningless bloat to pages.

    THANK YOU

Viewing 2 replies - 1 through 2 (of 2 total)
  • You could remove classes by filtering them out with the nav_menu_css_class filter. For example, this would remove all classes on wp_nav_menu() where you pass no_classes => true as an argument.

    <?php
    function my_remove_nav_menu_classes( $classes, $item, $args ) {
        if ( $args['no_classes'] ) {
            $classes = array();
        }
    
        return $classes;
    }
    add_filter( 'nav_menu_css_class', 'my_remove_nav_menu_classes', 99, 3 );

    Add that to your theme’s, or preferably Child Theme’s, functions.php file.

    Thread Starter filoveg

    (@filoveg)

    When passed no_classes => true there isn’t that variable in $args in function filter. But it doesn’t matter, I did a little research and came up with this which is simpler 🙂

    // cleaner nav menu
    add_filter( 'nav_menu_css_class', '__return_empty_array', 99, 3 );
    add_filter('nav_menu_item_id', '__return_empty_array', 99, 3 );

    Thank you! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Cleaner wp_nav_menu’ is closed to new replies.