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.

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. Commented May 1, 2019 at 14:33

2 Answers 2

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') 
); 
1
  • my-custom-menu in REGISTER_NAV_MENU is different from THEME_LOCATION's one reason why Commented May 1, 2019 at 14:41
1

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', 
) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.