WordPress: wp_nav_menu – add class on UL?

WordPress: wp_nav_menu – add class on UL?

Asked on October 25, 2018 in Wordpress.
Add Comment


  • 4 Answer(s)

    We can use the wp_nav_menu to the parameters:

    <?php
    $args = array(
        'menu_class' => 'nav nav-tabs',
        'menu' => '(your_menu_id)'
    );
    wp_nav_menu( $args );
    ?>
    

     

    Answered on October 25, 2018.
    Add Comment

    The element, which in our case ‘ul’ tag, and than we can specify the class and then we can assign in the ‘menu_class’. And then the sample code is below:

    wp_nav_menu( array(
        'theme_location' => 'top-menu',
        'container' => 'ul',
        'menu_class'=> '[add-your-class-here]'
    ) );
    

     

    Answered on October 25, 2018.
    Add Comment

    We have to add the class to the ul of wp_nav_menu. Use the code:

    <?php
    $defaults = array(
        'menu_class'      => 'menu',
        'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    );
    wp_nav_menu( $defaults );
    ?>
    

    As per the wordpress codex as were are changing the menu from ‘menu_class’ => ‘menu’, and also we can change the class of the ul , instead we can make the changes of the class of the div wrapping with the ul.

     

    Answered on October 25, 2018.
    Add Comment
    <?php 
    $args = array(
        'menu_class' => 'nav nav-tabs',        
        'menu' => '(your_menu_id)'
    );
    wp_nav_menu( $args ); 
    ?>
    Answered on February 18, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.