wp_get_nav_menu_name( string $location ): string

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. View all references

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 ↑

Hooks



Top ↑

Changelog

Changelog
Version Description
4.9.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by pixelstorm

    Output the name of the menu before displaying the menus items to the user.

    $locations = get_nav_menu_locations();
    $menu = wp_get_nav_menu_object( $locations['registered-menu-location-slug'] );
    echo '<div class="footer-menu__title">' . wp_kses_post( $menu->name ) . '</div>';

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