admin管理员组文章数量:1430513
I'm using a theme based on underscores, and I have registered my menus in the following way.
function register_my_menu() {
register_nav_menus( array(
'primary' => esc_html__( 'Primary' ),
'social_media' => esc_html__( 'Social Media' ),
) );
};
add_action( 'init', 'register_my_menu' );
When calling the menus like so:
wp_nav_menu(
['theme_location' => 'primary']
);
wp_nav_menu(
['theme_location' => 'social_media']
);
only the primary menu shows up.
I checked if themenu exists and is registered with has_nav_menu()
and it returns true
.
Here is my backend. The menu is registered and assigned to a location:
No, it's not on display none. I checked the markup, and it's empty.
I disabled JS and it's still the same. I tried adding a new menu:
…
'secondary' => esc_html__( 'Secondary' ),
…
and went through all the procedure, and when calling
wp_nav_menu(
['theme_location' => 'secondary']
);
nothing happens. Markup is still empty. Somehow it's only working with the name 'primary'
I'm using a theme based on underscores, and I have registered my menus in the following way.
function register_my_menu() {
register_nav_menus( array(
'primary' => esc_html__( 'Primary' ),
'social_media' => esc_html__( 'Social Media' ),
) );
};
add_action( 'init', 'register_my_menu' );
When calling the menus like so:
wp_nav_menu(
['theme_location' => 'primary']
);
wp_nav_menu(
['theme_location' => 'social_media']
);
only the primary menu shows up.
I checked if themenu exists and is registered with has_nav_menu()
and it returns true
.
Here is my backend. The menu is registered and assigned to a location:
No, it's not on display none. I checked the markup, and it's empty.
I disabled JS and it's still the same. I tried adding a new menu:
…
'secondary' => esc_html__( 'Secondary' ),
…
and went through all the procedure, and when calling
wp_nav_menu(
['theme_location' => 'secondary']
);
nothing happens. Markup is still empty. Somehow it's only working with the name 'primary'
1 Answer
Reset to default 1If found out that this is removing my menu:
function add_menu_icon ( $items, $args ) {
if ( $args->theme_location == 'primary' ) {
$elements = '<li class="custom-logo">'
. get_custom_logo() .
'</li>';
$elements .= $items;
$items = $elements;
return $items;
}
}
add_filter( 'wp_nav_menu_items', 'add_menu_icon', 10, 2 );
I still haven't figured out why.
本文标签: phpwpnavmenu not working correctly in my underscores theme
版权声明:本文标题:php - wp_nav_menu not working correctly in my underscores theme 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745496865a2660845.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
secondary
menu? – Nilambar Sharma Commented May 13, 2019 at 8:19