Removing container from wp_nav_menu not working

I’m converting this html menu to wordpress:

    <li><a href="" class="current"><span>Home</span></a></li>
    <li><a href=""><span>About</span></a></li>

i use:

 'menu'=>'mainmenu' ,
 'container'       => false, 
 'link_before'     => '<span>',
 'link_after'      => '</span>',
 'theme_location'  => 'primary')

but the html i get is:

<div class="menu">
        <li class="current_page_item"><a href="http://localhost/goodsoil/" title="Home"><span>Home</span></a></li>
        <li class="page_item page-item-2"><a href="http://localhost/goodsoil/?page_id=2" title="About"><span>About</span></a></li>

If i use a custom menu then i get:

<ul id="menu-test" class="menu">
    <li id="menu-item-6" class="menu-item menu-item-type-custom current-menu-item current_page_item menu-item-home menu-item-6"><a href=""><span>Home</span></a></li>
    <li id="menu-item-5" class="menu-item menu-item-type-post_type menu-item-5"><a href="url/?page_id=2"><span>About</span></a></li>

but if i don’t use a custom menu ‘container’=>false doesn’t work
Any solution?


IT DOES NOT WORK when you are referring to an inexisting location. e.g. when you copied the code from somewhere else, or you haven’t created your menu or location yet in the dasboard.

e.g. remove “, ‘theme_location’ => ‘primary'” from the following code:

    wp_nav_menu( array( 'container'=> false, 'menu_class'=> false, 'menu_id'=> 'ia_toplevel', 'theme_location' => 'primary' ) );

so it shoult look like

    wp_nav_menu( array( 'container'=> false, 'menu_class'=> false, 'menu_id'=> 'ia_toplevel' ) );

It works fine WITHOUT container in my website

Leave a Comment