Remove wrapping div and ul from output of wp_nav_menu

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:

Read More
<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 🙁

Related posts

Leave a Reply

6 comments

  1. 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;
    }
    
  2. 2021

    Tested and Working ✔

    To remove <div>

    Use container => false or container => '' inside wp_nav_menu.

    wp_nav_menu( 
        array( 
            'container' => false
        ) 
    );
    

    Still not working?

    Do not add theme_location to your wp_nav_menu. If you do you will still see the <div> container.

    wp_nav_menu( 
        array( 
            'container' => false,
            'theme_location' => 'Primary Menu'
        ) 
    ); 
    

    To remove the <ul>

    If you want to remove the <ul> wrapper, use this. Based on @Mill answer.

    wp_nav_menu( 
        array( 
            'container' => '',
            'items_wrap' => '%3$s'
        ) 
    ); 
    

    If you need control on <ul> elements

    If you want to retain all elements inside the <ul> from orignal WordPress id and class use this 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>' based on @woodchucky answer.

    wp_nav_menu( 
        array( 
            'container' => '',
            'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>'
        ) 
    );