WP_REST_Menus_Controller::get_menu_locations() WordPress Method

The WP_REST_Menus_Controller::get_menu_locations() method is used to get the list of available menu locations for a given theme. This is useful for determining where a particular menu can be displayed on a site.

WP_REST_Menus_Controller::get_menu_locations( int $menu_id ) #

Returns the names of the locations assigned to the menu.


Parameters

$menu_id

(int)(Required)The menu id.


Top ↑

Return

(string[]) The locations assigned to the menu.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php

	protected function get_menu_locations( $menu_id ) {
		$locations      = get_nav_menu_locations();
		$menu_locations = array();

		foreach ( $locations as $location => $assigned_menu_id ) {
			if ( $menu_id === $assigned_menu_id ) {
				$menu_locations[] = $location;
			}
		}

		return $menu_locations;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.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.