Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove <div> wrapper from wp_nav_menu output

Tags:

wordpress

I'm trying to remove the wrapper from the wp_nav_menu() function.

I've passed container => false to the arguements array and added a hook in my functions.php, but it still shows the wrapper.

function my_wp_nav_menu_args( $args )
{
    $args['menu'] = false;
    $args['menu_class'] = false;
    $args['container'] = false;
    $args['container_class'] = false;
    $args['show_home'] = true;

    return $args;
}

Any ideas why?

like image 718
user987460 Avatar asked Oct 10 '11 09:10

user987460


1 Answers

Reading the codex: Function Reference/wp nav menu

You may need to set the Theme Location in your functions.php file and then assign your menu to it?

This is what is says in the codex:

In order to remove navigation container, theme location specified in functions.php and used among arguments in function wp_nav_menu ( eg. 'theme_location' => 'primary-menu' ) must have a menu assigned to it in administration! Othervise argument 'container' => 'false' is ignored.

If you need to register a location you can use the following:

// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
    'primary' => __( 'Primary Navigation', 'Your_Theme' ),
) );

Then pass it in the wp_nav_menu() function

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

Hope this helps!

like image 141
daveaspinall Avatar answered Oct 13 '22 11:10

daveaspinall