get_nav_menu_locations(): int[]
Retrieves all registered navigation menu locations and the menus assigned to them.
Return
int[] Associative array of registered navigation menu IDs keyed by their location name. If none are registered, an empty array.
Source
File: wp-includes/nav-menu.php
.
View all references
function get_nav_menu_locations() {
$locations = get_theme_mod( 'nav_menu_locations' );
return ( is_array( $locations ) ) ? $locations : array();
}
Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Allows the editor role to modify menus
Just to Update on the ‘return’ statement, it returns ‘integer’ for individual ‘menu-location’ if no menu is assigned. To be precise, it returns an Array like so:
Returns an array like so
Array
(
[main-menu] => 757
[mobile-menu] => 1506
[footer-menu] => 0
)
main-menu and mobile-menu are assigned so they return Menu ID whereas footer-menu is unassigned and thus returns ‘0’.