WordPress.org

Support

Support » How-To and Troubleshooting » Problem with wp_nav_menu() – hiding menu container

Problem with wp_nav_menu() – hiding menu container

  • Hi all.
    I need to hide the menu container and to change the UL class.
    Reference:
    http://codex.wordpress.org/Function_Reference/wp_nav_menu

    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…

Viewing 6 replies - 1 through 6 (of 6 total)
  • Perhaps you need to register the menu with register_nav_menu.

    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, …).

    https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/post-template.php#L898

    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>
        ...snip...
      </ul>
    </div>

    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.

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

    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.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Problem with wp_nav_menu() – hiding menu container’ is closed to new replies.
Skip to toolbar