WordPress.org

Ready to get started?Download WordPress

Forums

wp_nav_menu() 'menu_class' usage? (bug?) (4 posts)

  1. DMackCA
    Member
    Posted 3 years ago #

    Hello,
    I'm trying to set the class on the ul element generated by the wp_nav_menu function.

    I'm using this php code:
    <?php wp_nav_menu(array('menu_class' => 'menuclass', 'container_class' => 'containerclass')); ?>

    I'd expect it to apply 'menuclass' to the ul, and 'containerclass' to the container div... But it doesn't. It prints like this:

    <div class="menuclass">
    <ul>
    <li class="current_page_item"><a title="Home" href="#">Page 1</a></li>
    <li><a href="#">Page 2</a>
    </ul>
    </div>

    Is this a bug in the way the function works, or is the documentation incorrect?

  2. lessthanweb
    Member
    Posted 3 years ago #

    Yup, having the same problem.

    If the menu (WP admin area) is not set, then the "menu_class" is applied to "container".
    In other words, it overwrites the "container_class".

    If the menu is set, then the "menu_class" is applied to "ul".

    I'm guessing this is a bug as it doesn't make any sense at all.

  3. lessthanweb
    Member
    Posted 3 years ago #

    Ah, its because of the fallback to wp_page_menu function if there is no menu set.

  4. aguimaraes
    Member
    Posted 3 years ago #

    You are right, it's because of the fallback to wp_page_menu.

    But, how can I set options for wp_page_menu when wp_nav_menu falls back?

Topic Closed

This topic has been closed to new replies.

About this Topic