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