benraaa
Member
Posted 11 months ago #
I need wp_nav_menu to show only if it has a menu item inside. Otherwise the menu as well as its wrapper should not appear at all. I thought this could have been done with the parameter $fallback_cb, if it is left empty. But it didn't work. Maybe it's possible to put something like if ( !empty () ); around it. But I don't know how to call the menu for an existing item. Does somebody know how to do?
My menu looks like this:
<?php
wp_nav_menu( array( 'theme_location' => 'pin', 'fallback_cb' => '', 'container' => 'div', 'items_wrap' => '<ul><li class="start">++</li> %3$s <li class="end">++</li></ul>' ) );
?>
I do not have a quick answer but I can maybe point you to one: If one creates a custom menu in WP3.3.2, and does not add anything to it, assigns it properly to a location, it does not show = there will be no nav menu there at all (at least in the Twenty Eleven theme), so such code exists there...
benraaa
Member
Posted 11 months ago #
Thanks for your really quick reply. So I will have a look for the newest Twenty Eleven. It will take some hours, since I have to do some other business first. But I will answer then.
[ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]
You can use the parameter fallback_cb but you would need to set it "false" like this:
<?php
wp_nav_menu( array( 'theme_location' => 'pin', 'fallback_cb' => <strong>false</strong>, 'container' => 'div', 'items_wrap' => '
<ul><li class="start">++ %3$s <li class="end">++</ul>
' ) );
?>