Ready to get started?Download WordPress


Problem with wp_nav_menu() - hiding menu container (7 posts)

  1. Mattia Roccoberton
    Posted 6 months ago #

    Hi all.
    I need to hide the menu container and to change the UL class.

    So my options are:
    wp_nav_menu( array( 'theme_location' => 'primary', 'container_class' => false, 'container' => '', 'menu_class' => 'my-menu' ) );

    This line works only if a primary menu is specified, otherwise the fallback_cb points to wp_page_menu() and 'container_class' / 'container' are ignored.

    It seems a bug to me...

  2. WPShowCase
    Posted 6 months ago #

    Perhaps you need to register the menu with register_nav_menu.

  3. Mattia Roccoberton
    Posted 6 months ago #

    Nav Menu already registered in my functions.php \ 'after_setup_theme' action.

    IMO the problem is that "wp_page_menu" function seems to ignore some of the options of "wp_nav_menu" (container, container_class, ...).


  4. Trippnology
    Posted 5 months ago #

    Experiencing the same problem as Mat. Options passed in when calling the menu are not being applied correctly.

    I'm calling the menu like so:

    <?php wp_nav_menu( array(
      'theme_location' => 'primary',
      'container' => false,
      'menu_class' => 'list-inline'
    ) ); ?>

    Which results in the following markup:

    <div class="list-inline">
      <ul class=" nav-menu">
        <li class="current_page_item">Home</li>

    The menu class is actually being applied to the wrapper div, which shouldn't even be there. I'm with Mat on the cause of this, see link in previous post.

  5. Trippnology
    Posted 5 months ago #

    Has this been recognised as a bug? Definitely something wonky going on!

  6. Trippnology
    Posted 5 months ago #

    Just realised that I was using the default menu. When I created a custom menu, the container and classes were applied correctly.

    Give it a try, Mat.

  7. Mattia Roccoberton
    Posted 3 weeks ago #

    Thank you for the tip. If I create a menu it works.
    But I think it should also work with the auto generated menu...


You must log in to post.

About this Topic