I have 2 menus that I've registered in my functions.php
add_action( 'after_setup_theme', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'primary', __( 'Primary Menu', 'visio' ) );
register_nav_menu( 'onepage', __( 'One Page Menu', 'visio' ) );
}
The One Page Menu
should only display on the frontpage, which is using a custom page template template-parts/page-homepage.php
And the Primary Menu
should display on all other pages.
However, when I create the if condition in my header.php
- it doesn't work, it always displays the One Page Menu
on the frontpage and on all other pages.
if(is_page_template('template-parts/page-homepage.php')) {
wp_nav_menu(
array (
'menu' => 'onepage',
'container' => false,
'container_id' => false,
'menu_class' => 'nav navbar-nav',
'menu_id' => false,
'depth' => 2,
'walker' => new Description_Walker
)
);
} else {
wp_nav_menu(
array (
'menu' => 'primary',
'container' => false,
'container_id' => false,
'menu_class' => 'nav navbar-nav',
'menu_id' => false,
'depth' => 2,
'walker' => new Description_Walker
)
);
}
What am I doing wrong? And how can I make this work?