上述功能的真正工作不是获取位置,而是获取位置及其内部的菜单。类似于array($location1 => $menu_id1,);. 因此,这些函数不会列出空位置。如果要获取所有填充位置和空位置,可能需要将以下内容添加到函数中。php文件:
//// here is how you register your menu locations
function register_my_menus()
{
    register_nav_menus(
        array(
            \'high-menu\' => __(\'top menu\'),
            \'main-menu\' => __(\'main menu\'),
            \'sec-menu\' => __(\'sec menu\'),
            \'thrd-menu\' => __(\'thrd menu\'),
        )
    );
}
add_action(\'init\', \'register_my_menus\');
//// This is our new function to get all menu locations
function get_all_menus_locations(){
    //// sadly we have to init them like this. I couldn\'t find any other way yet
    $all_location = array(
        \'high-menu\',
        \'main-menu\',
        \'sec-menu\' ,
        \'thrd-menu\',        
    );
    //// this is the original function which gets only filled locations
    $locations = get_nav_menu_locations();
    
    //// this is our new variable. we will fill it by all locations
    $registered_nav_menus= [];
    foreach($all_locations as $location){
        if(isset($locations[$location])){
            //// if the location had a menu inside...
            $registered_nav_menus[$location] = $locations[$location];
        }
        else {
            ////if location was empty, set a new value for it.
            $registered_nav_menus[$location] = \'\';
        }
    }
    return $registered_nav_menus;
}
 这不是我一直在寻找的解决方案,但这是我所做的。现在我正在使用它,如果你有更好的,请分享。