How to check if a menu with name, for example 'topnavbar' exists in WordPress 3?
has_nav_menu() sounds like what you're looking for. http://codex.wordpress.org/Function_Reference/has_nav_menu
If you take a look at the code for the wp_nav_menu
function, one of the first things it does is get the menu with that name, using the wp_get_nav_menu_object
function. This function will return the menu, or false if it doesn't exist
There is conditional tag is_nav_menu( $id )
which checks if the given id, slug or name is a navigation menu:
if ( is_nav_menu( 'topnavbar' ) ) {
// do something
}
Codex: https://codex.wordpress.org/Function_Reference/is_nav_menu
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With