Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 :(

share|improve this question

4 Answers 4

up vote 10 down vote accepted

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!).

share|improve this answer
    
Thanks a lot man! It works now. I was not familiar with PHP and did not know that I need to put the add_filter to the functions.php. –  Tuan Anh Oct 6 '10 at 23:11
    
That still doesn't explain how to remove the div, which rather wraps up the wrap_class explained above. The container argument set to false doesn't work. –  sergio Apr 25 '11 at 21:50
1  
If the container argument doesn't work, that means you're not using wp_nav_menu. You're probably running the fallback cb, which defaults to wp_page_menu(), by failing to specify either a menu, or a menu location with an assigned menu. –  John P Bloch Apr 26 '11 at 21:03

'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

share|improve this answer

To filter out the wrapping div:

add_filter('wp_nav_menu_args', 'prefix_nav_menu_args');
function prefix_nav_menu_args($args = ''){
    $args['container'] = false;
    return $args;
}
share|improve this answer

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> tag

share|improve this answer
    
Heh, cool! And welcome to WPSE @woodchucky! –  toscho Apr 25 '11 at 23:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.