wp_get_nav_menu_name() WordPress Function

The wp_get_nav_menu_name() function allows you to get the name of a nav menu. This is useful if you need to programmatically output the name of a nav menu in your theme or plugin.

wp_get_nav_menu_name( string $location ) #

Returns the name of a navigation menu.


Parameters

$location

(string)(Required)Menu location identifier.


Top ↑

Return

(string) Menu name.


Top ↑

Source

File: wp-includes/nav-menu.php

function wp_get_nav_menu_name( $location ) {
	$menu_name = '';

	$locations = get_nav_menu_locations();

	if ( isset( $locations[ $location ] ) ) {
		$menu = wp_get_nav_menu_object( $locations[ $location ] );

		if ( $menu && $menu->name ) {
			$menu_name = $menu->name;
		}
	}

	/**
	 * Filters the navigation menu name being returned.
	 *
	 * @since 4.9.0
	 *
	 * @param string $menu_name Menu name.
	 * @param string $location  Menu location identifier.
	 */
	return apply_filters( 'wp_get_nav_menu_name', $menu_name, $location );
}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.