wp_get_nav_menu_object

Returns a navigation menu object.

Description

(object|false) wp_get_nav_menu_object( (string) $menu ); 

Returns (object|false)

False if $menu param isn't supplied or term does not exist, menu object if successful.

Parameters (1)

0. $menu (string)
Menu ID, slug, or name - or the menu object.

Usage

  1. if ( !function_exists( 'wp_get_nav_menu_object' ) ) { 
  2. require_once ABSPATH . WPINC . '/nav-menu.php'; 
  3.  
  4. // Menu ID, slug, or name - or the menu object. 
  5. $menu = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_get_nav_menu_object($menu); 
  9.  

Defined (1)

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

/wp-includes/nav-menu.php  
  1. function wp_get_nav_menu_object( $menu ) { 
  2. $menu_obj = false; 
  3.  
  4. if ( is_object( $menu ) ) { 
  5. $menu_obj = $menu; 
  6.  
  7. if ( $menu && ! $menu_obj ) { 
  8. $menu_obj = get_term( $menu, 'nav_menu' ); 
  9.  
  10. if ( ! $menu_obj ) { 
  11. $menu_obj = get_term_by( 'slug', $menu, 'nav_menu' ); 
  12.  
  13. if ( ! $menu_obj ) { 
  14. $menu_obj = get_term_by( 'name', $menu, 'nav_menu' ); 
  15.  
  16. if ( ! $menu_obj || is_wp_error( $menu_obj ) ) { 
  17. $menu_obj = false; 
  18.  
  19. /** 
  20. * Filters the nav_menu term retrieved for wp_get_nav_menu_object(). 
  21. * @since 4.3.0 
  22. * @param object|false $menu_obj Term from nav_menu taxonomy, or false if nothing had been found. 
  23. * @param string $menu The menu ID, slug, or name passed to wp_get_nav_menu_object(). 
  24. */ 
  25. return apply_filters( 'wp_get_nav_menu_object', $menu_obj, $menu );