最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - how to display a specific wordpress menu?

programmeradmin1浏览0评论

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 and theme_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
Add a comment  | 

2 Answers 2

Reset to default 2

Register 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', 
) );
发布评论

评论列表(0)

  1. 暂无评论