Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPavle Lucic
10,801 Pointswp_nav_menu container set to False not working
Have problem with wp_nav_menu function.
<?php
$defaults = array (
'container' => false,
'theme_location' => 'Primary_menu',
'menu_class' => 'menu',
);
wp_nav_menu ( $defaults );
?>
Container => false is NOT removing div. It stills output container around <ul>. I cannot figure what is the problem?
4 Answers
Pavle Lucic
10,801 PointsMaybe I have fix problem, but not sure is it proper way to do that.
I added in array
'menu' => 'Menu name here'
so it worked out.
Scott Carver
1,165 Points<?php
This is working for me currently:
$menu = array(
'theme_location' => 'primary-desktop',
'container' => '',
'items_wrap' => '%3$s'
);
wp_nav_menu( $menu );
Seems like the container=>false technique doesn't work anymore (using WP 4.5). In the docs there is an example that shows the a similar use of items_wrap minus the "container" set to a blank string that also doesn't work currently https://developer.wordpress.org/reference/functions/wp_nav_menu/#comment-204 Given that those two techniques seemed to work previously, it's hard to say if this will work foreverever either.
?>
Sergio Alen
26,726 PointsI dont think 'container' is a boolean i might be wrong, have you try leaving it blank? 'container' => ' ',
Pavle Lucic
10,801 PointsTry with blank also, not working
Luke Pettway
16,593 Points$container (string) (optional) Whether to wrap the ul, and what to wrap it with. Allowed tags are div and nav. Use false for no container e.g. 'container' => false Default: div
That is from the Codex. Using false should work. What is the HTML markup, are you sure the wrapper around it isn't hardcoded there already?
Anthony Lucio
20,431 PointsAnthony Lucio
20,431 PointsUnder header.php I entered the following:
<?php