How to check if a menu with name, for example ‘topnavbar’ exists in WordPress 3?
Leave a Reply
You must be logged in to post a comment.
How to check if a menu with name, for example ‘topnavbar’ exists in WordPress 3?
You must be logged in to post a comment.
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 thewp_get_nav_menu_object
function. This function will return the menu, or false if it doesn’t existThere is conditional tag
is_nav_menu( $id )
which checks if the given id, slug or name is a navigation menu:Codex: https://codex.wordpress.org/Function_Reference/is_nav_menu