has_nav_menu

Filters whether a nav menu is assigned to the specified location.

Description

apply_filters( 'has_nav_menu', (bool) $has_nav_menu, (string) $location ); 

Parameters (2)

0. $has_nav_menu (bool)
Whether there is a menu assigned to a location.
1. $location (string)
Menu location.

Usage

To run the hook, copy the example below.
  1. $has_nav_menu = apply_filters( 'has_nav_menu', $has_nav_menu, $location ); 
  2.  
  3. if ( !empty( $has_nav_menu ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the has_nav_menu callback 
  2. function filter_has_nav_menu( $has_nav_menu, $location ) { 
  3. // make filter magic happen here... 
  4. return $has_nav_menu
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'has_nav_menu', 'filter_has_nav_menu', 10, 2 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'has_nav_menu', 'filter_has_nav_menu', 10, 2 ); 

Defined (1)

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

/wp-includes/nav-menu.php  
  1. return apply_filters( 'has_nav_menu', $has_nav_menu, $location );