Removing container from wp_nav_menu not working

I’m converting this html menu to wordpress:

<ul>
    <li><a href="https://wordpress.stackexchange.com/" class="current"><span>Home</span></a></li>
    <li><a href="https://wordpress.stackexchange.com/"><span>About</span></a></li>
</ul>

i use:

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

but the html i get is:

<div class="menu">
    <ul>
        <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>
    </ul>
</div>

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="https://wordpress.stackexchange.com/questions/3775/url/"><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>
</ul>

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

6

[SOLVED]
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 SocialBlogsiteWebDesign.com

Leave a Comment