admin管理员组文章数量:1024133
Below is my code:
wp_nav_menu( array(
'menu', _('My Custom Header Menu'),
'theme_location' => 'my_custom_location',
) );
And as result, I obtain all Wordpress page's menu link instead of the menu of My Custom Header Menu.
Below is my code:
wp_nav_menu( array(
'menu', _('My Custom Header Menu'),
'theme_location' => 'my_custom_location',
) );
And as result, I obtain all Wordpress page's menu link instead of the menu of My Custom Header Menu.
Share Improve this question asked May 1, 2019 at 13:53 dzogbenyui agblevondzogbenyui agblevon 31 bronze badge 3 |2 Answers
Reset to default 2Register your navigation menu
Add this code to your functions.php file.
function my_custom_new_menu() {
register_nav_menu('my-custom-menu',__( 'My Custom Menu' ));
}
add_action( 'init', 'my_custom_new_menu' );
Create new menu
You can now go to Appearance » Menus page in your WordPress admin and try to create or edit a new menu. You will see ‘My Custom Menu’ as theme location option.
Display new menu
wp_nav_menu( array(
'theme_location' => 'my-custom-menu')
);
First check if you have already registred a menu location with the same name :
register_nav_menus( array(
'my_custom_location' => 'My Custom location',
) );
Secondly, i don't think you need this : 'menu', _('My Custom Header Menu'), and instead just keep your code as bellow :
wp_nav_menu( array(
'theme_location' => 'my_custom_location',
) );
Below is my code:
wp_nav_menu( array(
'menu', _('My Custom Header Menu'),
'theme_location' => 'my_custom_location',
) );
And as result, I obtain all Wordpress page's menu link instead of the menu of My Custom Header Menu.
Below is my code:
wp_nav_menu( array(
'menu', _('My Custom Header Menu'),
'theme_location' => 'my_custom_location',
) );
And as result, I obtain all Wordpress page's menu link instead of the menu of My Custom Header Menu.
Share Improve this question asked May 1, 2019 at 13:53 dzogbenyui agblevondzogbenyui agblevon 31 bronze badge 3-
Your parameters array is a mix of standalone entries and key value pairs, are you sure
'menu', _(...), 'theme_location' => '...'
is what you intended? mixing[1,2,3]
and[ 'foo' => 'bar' ]
style array items is not normal – Tom J Nowell ♦ Commented May 1, 2019 at 13:58 -
Also, are you trying to render a specific menu theme location? You're specifying both
menu
andtheme_location
which is a paradox, "show this specific menu, no actually show the menu at this theme menu location" – Tom J Nowell ♦ Commented May 1, 2019 at 14:00 - My custom menu theme location is a hook. And I successfully come out to display menu items over there. Now I need to specify to wp_nav_menu, to display only the menu items of My Custom Header Menu. – dzogbenyui agblevon Commented May 1, 2019 at 14:33
2 Answers
Reset to default 2Register your navigation menu
Add this code to your functions.php file.
function my_custom_new_menu() {
register_nav_menu('my-custom-menu',__( 'My Custom Menu' ));
}
add_action( 'init', 'my_custom_new_menu' );
Create new menu
You can now go to Appearance » Menus page in your WordPress admin and try to create or edit a new menu. You will see ‘My Custom Menu’ as theme location option.
Display new menu
wp_nav_menu( array(
'theme_location' => 'my-custom-menu')
);
First check if you have already registred a menu location with the same name :
register_nav_menus( array(
'my_custom_location' => 'My Custom location',
) );
Secondly, i don't think you need this : 'menu', _('My Custom Header Menu'), and instead just keep your code as bellow :
wp_nav_menu( array(
'theme_location' => 'my_custom_location',
) );
本文标签: customizationhow to display a specific wordpress menu
版权声明:本文标题:customization - how to display a specific wordpress menu? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745535371a2154936.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'menu', _(...), 'theme_location' => '...'
is what you intended? mixing[1,2,3]
and[ 'foo' => 'bar' ]
style array items is not normal – Tom J Nowell ♦ Commented May 1, 2019 at 13:58menu
andtheme_location
which is a paradox, "show this specific menu, no actually show the menu at this theme menu location" – Tom J Nowell ♦ Commented May 1, 2019 at 14:00