Reputation: 12029
When I have my wordpress menu code in my index.php file everything works fine. The wrapper in a tag with the appropriate ID but when I move the navigation code to my header file or any other file and include it in my index template the navigation wrapper becomes a and does not have the appropriate ID's any clue whats going on? Here is my code
FUNCTIONS.php
<?php
register_nav_menus(
array(
'main-nav-header-top' => 'Main Nav'
)
);
$main_menu_header_top = array(
'theme_location' => 'main-nav-header-top',
'container' => 'nav',
'container_id' => 'mainNavigation',
'menu_id' => 'mobileNav',
'depth' => 0,
);
?>
And here is my code I want to put in my header.php file
<?php wp_nav_menu( $main_menu_header_top ); ?>
Upvotes: 0
Views: 104
Reputation: 260
remove dashes and replase with underscore
main-nav-header-top
to main_nav_header_top
Upvotes: 1
Reputation: 15949
<?php wp_nav_menu( array('menu' => 'Main Nav' )); ?>
and don't forget to check the appearance → Menus panel.
you can debug using get_registered_nav_menus()
to see if the menu is registered correctly ..
also ..
You will be better off wrapping it in a function and hooking to init ...
function my_custom_menus() {
$locations = array(
'header_menu' => __( 'main-nav-header-top', 'Main Nav' ),
'footer_menu' => __( 'Custom Footer Menu', 'text_domain' ),
'mobile_footer' => __( 'Footer Menu on mobile devices', 'text_domain' ),
);
register_nav_menus( $locations );
}
add_action( 'init', 'my_custom_menus' );
Upvotes: 1