Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if menu with specific name exists

Tags:

wordpress

How to check if a menu with name, for example 'topnavbar' exists in WordPress 3?

like image 455
Sergei Basharov Avatar asked Oct 23 '10 12:10

Sergei Basharov


3 Answers

has_nav_menu() sounds like what you're looking for. http://codex.wordpress.org/Function_Reference/has_nav_menu

like image 142
CoryDuncan Avatar answered Oct 24 '22 06:10

CoryDuncan


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

like image 7
Damian Jakusz-Gostomski Avatar answered Oct 24 '22 05:10

Damian Jakusz-Gostomski


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

like image 2
Damian Wajer Avatar answered Oct 24 '22 06:10

Damian Wajer