has_nav_menu

Determines whether a registered nav menu location has a menu assigned to it.

Description

has_nav_menu( (string) $location ); 

Parameters (1)

0. $location (string)
Menu location identifier.

Usage

  1. if ( !function_exists( 'has_nav_menu' ) ) { 
  2. require_once ABSPATH . WPINC . '/nav-menu.php'; 
  3.  
  4. // Menu location identifier. 
  5. $location = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = has_nav_menu($location); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/nav-menu.php  
  1. function has_nav_menu( $location ) { 
  2. $has_nav_menu = false; 
  3.  
  4. $registered_nav_menus = get_registered_nav_menus(); 
  5. if ( isset( $registered_nav_menus[ $location ] ) ) { 
  6. $locations = get_nav_menu_locations(); 
  7. $has_nav_menu = ! empty( $locations[ $location ] ); 
  8.  
  9. /** 
  10. * Filters whether a nav menu is assigned to the specified location. 
  11. * @since 4.3.0 
  12. * @param bool $has_nav_menu Whether there is a menu assigned to a location. 
  13. * @param string $location Menu location. 
  14. */ 
  15. return apply_filters( 'has_nav_menu', $has_nav_menu, $location );