I want to hide the div class “navmain2” if the menu is empty. See code below:
<!-- Start main navigation -->
<div class="navmain2">
<div id="logo"></div>
<!-- Gets main menu by id -->
<span></span>
<?php
wp_nav_menu( array(
'menu' => 11,
'container' =>false,
'menu_class' => 'nav',
'echo' => true,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => 0,
'walker' => new description_walker())
);
?>
<!-- /main menu -->
<div id="klicka">Click here! Click here! Click here</div>
</div><!-- /main navigation -->-->
I have a logo and a div with text inside navmain2 as you can see.
The question is:
Is it possible to hide the whole navmain2 div if the wp_nav_menu is empty?
Assign the menu to a string:
If you wanted to check there is a menu assigned you could use has_nav_menu(). Passing through the registered menu id as registered via register_nav_menu()
Note: This function will output the div if the location
primary
has a menu assigned, it will also output the div if the menu is assigned and emptyDetermines whether a registered nav menu location has a menu assigned to it. know more
Solution nr 2:
Is to hide the div thru Js.