The function wp_nav_menu takes an argument of fallback_cb which is the name of the function to run if the menu doesn’t exist. so change you code to something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
function wp_nav_menu_no_ul() { $options = array( 'echo' => false, 'container' => false, 'theme_location' => 'primary', 'fallback_cb'=> 'fall_back_menu' ); $menu = wp_nav_menu($options); echo preg_replace(array( '#^<ul[^>]*>#', '#</ul>$#' ), '', $menu); } function fall_back_menu(){ return; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.