admin管理员组文章数量:1314480
Why do my created Menus on the WordPress Admin dashboard appear in customtemplate.php
DESPITE not defining it the correct 'theme_location'
?
It will show in that location EVEN if the created menu in the WordPress Admin dashboard is not set to show in any location.
It only hides if the following if check is tested. Why?
if(has_nav_menu('menu-ID1'))
Functions.php
register_nav_menus(
array(
'menu-ID1' => __( 'MenuName', 'blabla' ),
)
);
customtemplate.php
//Still displays even though the registered menu-ID1 is not used
wp_nav_menu(['theme_location' => 'randomname']);
Why do my created Menus on the WordPress Admin dashboard appear in customtemplate.php
DESPITE not defining it the correct 'theme_location'
?
It will show in that location EVEN if the created menu in the WordPress Admin dashboard is not set to show in any location.
It only hides if the following if check is tested. Why?
if(has_nav_menu('menu-ID1'))
Functions.php
register_nav_menus(
array(
'menu-ID1' => __( 'MenuName', 'blabla' ),
)
);
customtemplate.php
//Still displays even though the registered menu-ID1 is not used
wp_nav_menu(['theme_location' => 'randomname']);
Share
Improve this question
edited Nov 24, 2020 at 6:56
Valeron
asked Nov 24, 2020 at 2:55
ValeronValeron
33 bronze badges
1 Answer
Reset to default 0I'm guessing your menu contains only Pages (posts of the page
type) on your site?
But nonetheless, with wp_nav_menu()
, if you specify a theme_location
that doesn't exist or contains no menu (i.e. no menus assigned to that location), then the fallback_cb
arg (which defaults to wp_page_menu()
) will determine what is displayed.
So if you want the function to display the menu only if it's assigned to the specified theme location, you can do the has_nav_menu()
check:
if ( has_nav_menu( 'menu-ID1' ) ) {
wp_nav_menu( 'theme_location=menu-ID1' );
}
or set the fallback_cb
to an empty string:
wp_nav_menu( array(
'theme_location' => 'menu-ID1',
'fallback_cb' => '',
) );
// or you may pass the function args as a query string:
wp_nav_menu( 'theme_location=menu-ID1&fallback_cb=' );
本文标签: navigationNav Menu Theme Location not working
版权声明:本文标题:navigation - Nav Menu: Theme Location not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741968825a2407708.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论