wp_get_nav_menus( array $args = array() ): WP_Term[]

Returns all navigation menu objects.

Parameters

$argsarrayoptional
Array of arguments passed on to get_terms() .
More Arguments from get_terms( … $args )Array or string of arguments. See WP_Term_Query::__construct() for information on accepted arguments.

Default:array()

Return

WP_Term[] An array of menu objects.

Source

function wp_get_nav_menus( $args = array() ) {
	$defaults = array(
		'taxonomy'   => 'nav_menu',
		'hide_empty' => false,
		'orderby'    => 'name',
	);
	$args     = wp_parse_args( $args, $defaults );

	/**
	 * Filters the navigation menu objects being returned.
	 *
	 * @since 3.0.0
	 *
	 * @see get_terms()
	 *
	 * @param WP_Term[] $menus An array of menu objects.
	 * @param array     $args  An array of arguments used to retrieve menu objects.
	 */
	return apply_filters( 'wp_get_nav_menus', get_terms( $args ), $args );
}

Hooks

apply_filters( ‘wp_get_nav_menus’, WP_Term[] $menus, array $args )

Filters the navigation menu objects being returned.

Changelog

VersionDescription
4.1.0Default value of the 'orderby' argument was changed from 'none' to 'name'.
3.0.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    After some work, I have summarized differences between some menu functions:
    var_dump( wp_get_nav_menus()); // returns all navigation objects
    var_dump( get_registered_nav_menus()); // returns registered menus
    var_dump( get_nav_menu_locations());
    // returns allocated menus to theme

    Menu Objects are like this:
    Menu object has: public ‘term_id’ => int 17
    Menu object has: public ‘term_id’ => int 18

    Registered menus in theme:
    array (size=2)
    ‘primary’ => string ‘Primary menu’ (length=12)
    ‘footer’ => string ‘Secondary menu’ (length=14)

    Locations point to used menus:
    array (size=2)
    ‘primary’ => int 17
    ‘footer’ => int 18

    So in this theme: only ‘primary’ and ‘footer’ exist in the theme and are used 17 for ‘primary’and 18 menu object for ‘footer’

You must log in before being able to contribute a note or feedback.