remove ul from wp nav menu wordpress

I am using twenty thirteen theme. I am using wp_nav_menu to display menu items. I need to remove the container div and ul from wp nav menu. I tried this.

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

But it’s not working. How to fix this?

Related posts

Leave a Reply

3 comments

  1. Even this question is quite old, I want to add a working solution. I found this question while searching for exactly the same, but the answer from Mark just removes the container not the ul or li tags of wp_nav_menu.

    Remove all <ul> and <li> tags from wp_nav_menu:

    function remove_wp_nav_menu_ul($menu){
       return preg_replace( array( '#^<ul[^>]*>#', '#</ul>$#', '#^<li[^>]*>#', '#</li>$#' ), '', $menu );
    }
    add_filter( 'wp_nav_menu', 'remove_wp_nav_menu_ul' );
    

    Just place that in the function.php of your theme. But before doing so, always consider to solve this with CSS before.

  2. Below code in functions.php

     function remove_wp_ul($menu){return preg_replace( array( '#^<ul[^>]*>#', '#</ul>$#', '#^<li[^>]*>#', '#</li>$#' ), '', $menu );}
    add_filter( 'wp_nav_menu', 'remove_wp_ul' );
    

    Inside header.php, write the following code:

    wp_nav_menu(array('menu' => 'mymenu','container' => false,)); ?>