I’m converting this html menu to wordpress:
<ul>
<li><a href="/" class="current"><span>Home</span></a></li>
<li><a href="/"><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="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?
[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:
so it shoult look like
It works fine WITHOUT container in my website SocialBlogsiteWebDesign.com
Found the solution.
Simply use “ul” for ‘container’
http://codex.wordpress.org/Function_Reference/wp_nav_menu
you are referring to the fallback function of the nav_menus. This is “wp_page_menu” and unfortunatelly it doesn’t produce the same type of markup that a custom menu does.
To fix this create your own fallback menu. I’m using this:
You might need to change this as my theme handles menus its own way, but I think you get the basic idea.
And when you’re calling
wp_nav_menu
do it likewp_nav_menu(array('fallback_cb' => 'my_page_menu'));
You can also match the classes to the ones of a custom menu using this:
This way you cut down a few CSS rules…
I developed a simple and efficient solution using
str_replace
, which can be applied separately for use in menu tables rather thanul li
:Try This