I am using the new menu system of WordPress, and here is the result of wp_nav_menu()
<div class="menu-main-menu-container">
<ul id="menu-main-menu" class="menu">
<li id="menu-item-28" class="menu-item menu-item-type-post_type current-menu-item page_item page-item-21 current_page_item menu-item-28"><a href="http://www.bemang.com/">Trang nhà </a></li>
<li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-29"><a href="http://www.bemang.com/blog/">Blog</a></li>
<li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-30"><a href="http://www.bemang.com/gioi-thieu/">Giá»i thiá»u</a></li>
</ul>
</div>
What I want is only this:
<li id="menu-item-28" class="menu-item menu-item-type-post_type current-menu-item page_item page-item-21 current_page_item menu-item-28"><a href="http://www.bemang.com/">Trang nhà </a></li>
<li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-29"><a href="http://www.bemang.com/blog/">Blog</a></li>
<li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-30"><a href="http://www.bemang.com/gioi-thieu/">Giá»i thiá»u</a></li>
No, wrapping div or ul, I have been trying to few ways and google around but no result 🙁
The wrapping div is easy. When you use
wp_nav_menu()
, add this argument:'container' => false
For the
<ul>
element, there’s an argument called'items_wrap'
. See woodchucky’s answer for more info on that one (and upvote it!).wp_nav_menu()
accepts an undocumented parameter‘items_wrap’ => ‘
<ul id="%1$s" class="%2$s">%3$s</ul>
‘This is executed by:
$nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items );
you can play around with the sprintf arguments
ex: ‘items_wrap’ => ‘%3$s’ would remove the wrapping
<ul>
tagFor outputting only li’s add this to wp_nav_menu array:
'container' => false
was failing for me because I was specifying a not existing'theme_location'
and'menu'
. It worked as soon as I fixed this.Solution from: wordpress.org/support
To filter out the wrapping div:
2021
Tested and Working â
To remove
<div>
Use
container => false
orcontainer => ''
insidewp_nav_menu
.Still not working?
Do not add
theme_location
to yourwp_nav_menu
. If you do you will still see the<div>
container.To remove the
<ul>
If you want to remove the
<ul>
wrapper, use this. Based on @Mill answer.If you need control on
<ul>
elementsIf you want to retain all elements inside the
<ul>
from orignal WordPressid
andclass
use this'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>'
based on @woodchucky answer.