I have specific wp menus for each url.
When I encounter a url that has no matching wp menu I dont want any nav. So far it seems if none is found it will show a default nav or pick one of the existing navs to show.

use case

http://domainnameA.com show wp_nav_menu('domainnameA')

http://domainnameB.com no menu exists - dont show a nav

instead I am getting Nav on Domain B that has a link to the only page that exists. If I delete the page I get no navigation but that is not a great solution.

  • would be great if you show us the piece of code you are using :) Nov 17 '11 at 4:00

Use has_nav_menu


$menu_name = sanitize_title($menu_name); // sanitize!

    wp_nav_menu(array('menu' => $menu_name));
  • this is close I am dynamically selecting my menus based on siteurl so I am using a variable to call the menu name. any idea if this would work with a variable instead of text?
    – aj martin
    Nov 21 '11 at 6:15
  • There's absolutely no reason not, afterall 'primarymenu' is just a hardcoded string variable
    – Tom J Nowell
    Nov 21 '11 at 10:08
  • `<?php $menu_name=$_SERVER['SERVER_NAME']; $menu_name=str_ireplace("WWW.","",$menu_name); $menu_name=str_ireplace(".","",$menu_name); ?> <div id="nav"> <?php wp_nav_menu( array('menu' =>$menu_name )); ?> </div>
    – aj martin
    Nov 21 '11 at 14:14
  • when I tried if(has_nav_menu($menu_name)) or if(has_nav_menu(array('menu' =>$menu_name ))) didnt seem to work
    – aj martin
    Nov 21 '11 at 14:18
  • that seems like a hackish way of generating $menu_name, for one have you checked the value of $menu_name and registered a menu of that name in your functions.php? You also forgot the http://
    – Tom J Nowell
    Nov 21 '11 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.