我遇到了一个非常奇怪的问题。
简要介绍一下背景:我从以前使用的工作流中克隆了此工作流,但只是更新了所有内容,包括节点包、gulp函数和工作流。这在以前工作得很好,现在突然出现错误,无法按预期工作。
因此,我尝试创建自定义菜单,并像往常一样注册它们:
register_nav_menus([
\'primary\' => \'Primary Menu\',
\'secondary\' => \'Footer Menu\',
\'tertiary\' => \'Legal Menu\'
]);
我注意到它根本不显示,但仍然显示在管理仪表板中,用于添加/删除项目。所以我做了一些测试,结果如下:
<?php
$menus = get_registered_nav_menus();
foreach ( $menus as $location => $description ) {
echo $location . \': \' . $description . \'<br />\';
}
echo has_nav_menu(\'primary\')?\'true<br />\':\'false<br />\';
$registered_nav_menus = get_registered_nav_menus();
echo isset( $registered_nav_menus[ \'primary\' ])?\'true<br />\':\'false<br />\';
$locations = get_nav_menu_locations();
var_dump($locations) ;
$locations = get_theme_mod( \'nav_menu_locations\' );
print_r($locations);
wp_nav_menu( array(
\'menu\' => \'primary\',
\'theme_location\' => \'primary\',
));
?>
这个代码给了我这个输出:
primary: Primary Menu
secondary: Footer Menu
tertiary: Legal Menu
false
true
array(0) { }
Array ( )
// These are not the correct menu items, it should only be showing the first 3. This is showing all pages on the website
Home
About
Contact
Privacy Policy
基本上,一些函数显示它已注册并显示已注册的菜单,而其他函数则显示它未注册。我通常不会在这里提问,因为这通常是我这边的一个错误,所以我最终设法找到了问题,但在这种情况下,我想不出任何其他原因,除非最新的WordPress版本中有错误。
如果有人能对此提供一些见解,那将是令人惊讶的,因为我完全被难住了!
WordPress版本:5.9PHP版本:7.4.27