Oct
24
2012

How to Remove the Menu Container DIV in WordPress

By Gabriel Harper Posted in

When you use the WordPress menu system and wp_nav_menu() function in your theme, menus will by default get wrapped in a <DIV> container. Since wp_nav_menu() displays list items, this ends up outputting invalid HTML. A <DIV> is not allowed as a direct descendant of a <UL> element.

Since this is invalid HTML, you’ll probably see an error validating your website:

Element div not allowed as child of element ul in this context.

In order to get rid of the container <DIV>, you can specify an empty container value in wp_nav_menu():

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

Now just make sure it didn’t FUBAR your CSS, and you should be all set.

About The Author

Gabriel Harper

Gabe is the owner and founder of Intavant, and contributes to Intavant Blog regularly with his expertise in design, development & business.

Did you find this article helpful? Please subscribe!