get_nav_menu_locations()

Retrieves all registered navigation menu locations and the menus assigned to them.


Description Description


Return Return

(array) Registered navigation menu locations and the menus assigned them. If none are registered, an empty array.


Top ↑

Source Source

File: wp-includes/nav-menu.php

function get_nav_menu_locations() {
	$locations = get_theme_mod( 'nav_menu_locations' );
	return ( is_array( $locations ) ) ? $locations : array();
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by khangaitan
    $menu_name = 'menu1';
    $menu_item = wp_get_nav_menu_object( get_nav_menu_locations( $menu_name )[ $menu_name ] )->name;
    
    echo $menu_item ? $menu_item : __( 'Insert menus', 'textdomain' );
    wp_nav_menu( array(
    	'theme_location' => $menu_name,
    	'container'      => ''
    ) );
    
    $menu_name = '';
    
    $menu_name = 'menu2';
    $menu_item = wp_get_nav_menu_object( get_nav_menu_locations( $menu_name )[ $menu_name ] )->name;
    
    echo $menu_item ? $menu_item : __( 'Insert menus', 'textdomain' );
    wp_nav_menu( array(
    	'theme_location' => $menu_name,
    	'container'      => ''
    ) );
    
    $menu_name = '';
    
    $menu_name = 'menu3';
    $menu_item = wp_get_nav_menu_object( get_nav_menu_locations( $menu_name )[ $menu_name ] )->name;
    
    echo $menu_item ? $menu_item : __( 'Insert menus', 'textdomain' );
    wp_nav_menu( array(
    	'theme_location' => $menu_name,
    	'container'      => ''
    ) );
    

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