我需要获取所有导航菜单位置。我尝试了以下方法:
get_nav_menu_locations();
get_theme_mod(\'nav_menu_location\');
它们都只返回填充的位置。我想要所有已填充和空的位置。我需要获取所有导航菜单位置。我尝试了以下方法:
get_nav_menu_locations();
get_theme_mod(\'nav_menu_location\');
它们都只返回填充的位置。我想要所有已填充和空的位置。上述功能的真正工作不是获取位置,而是获取位置及其内部的菜单。类似于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;
}
这不是我一直在寻找的解决方案,但这是我所做的。现在我正在使用它,如果你有更好的,请分享。我是一个自学成才的wordpress网站设计师,请原谅我的无知。我为一个客户开发的几个网站最近被一个印尼黑客组织破坏了(很有趣!)。客户端没有更新wordpress安装和其他一些危及安全的事情。遗憾的是,没有网站的清理备份。网络主机给了我一个包含恶意软件扫描结果的文本文件。看起来很多受影响的文件都是导航菜单。网站的php文件。文本文件中显示的扫描结果示例如下:“[主目录]/[网站文件夹名称]/wp includes/nav-menu.php:SL-php-INJECTOR-1-ejw.UNOFFICIAL