I’m creating a website with Divi builder. I’m currently editing the header.php
file and I’m having problems with applying a conditional menu. I’m currently using the primary menu for one page and the secondary menu for the other. Both work perfectly fine in desktop view but in the mobile dropdown, all items from both primary and secondary appear.
if(is_page(1)){
$primaryNav = wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => 'top-menu', 'echo' => false ) );
} else if (is_page(2)){
$primaryNav = wp_nav_menu( array( 'theme_location' => 'secondary-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => 'top-menu', 'echo' => false ) );
} else {
$primaryNav = wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => 'top-menu', 'echo' => false ) );
}
I believe this is for the mobile
$slide_nav = '';
$slide_menu_class = 'et_mobile_menu';
$slide_nav = wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'echo' => false, 'items_wrap' => '%3$s' ) );
$slide_nav .= wp_nav_menu( array( 'theme_location' => 'secondary-menu', 'container' => '', 'fallback_cb' => '', 'echo' => false, 'items_wrap' => '%3$s' ) );
2
Answers
This one has been resolved. Turns out the mobile nav was in the parent theme's functions.php
The solution was to add another menu in the register_nav_menus() function.
How is this drop down menu configured? maybe in your theme it is called by another function and actually only has items associated with it in admin. Check in the admin panel if there are no menus without being associated and if there is not yet put here an excerpt from where is the mobile menu to know if there is any coditional different from yours.
————–Updated after update——————
In your first code you can simplify it like this:
In your second code you can do it like this: