Today i present myself with another issue. In my own wordpress theme i created 2 nav menus: navbar_pc and navbar_mobile. When i try to implement these 2 navbars, only the mobile one shows up in the source code. here is the content of those files: navbar_pc:
<nav>
<?php
$argsforpcnavbar=array (
"theme-location" => "nav_pc"
);
wp_nav_menu($argsforpcnavbar);
?>
</nav>
and navbar_mobile:
<nav>
<?php
$argsformobilenavbar=array (
"theme-location" => "nav_mobile"
);
wp_nav_menu($argsformobilenavbar);
?>
</nav>
those are called in the header.php and registered as menus and header.php
<div >
<?php get_template_part("template_parts/navbar_pc"); ?>
<?php get_template_part("template_parts/navbar_mobile"); ?>
</div>
in the functions.php they are registered as follows:
function register_my_menus() {
register_nav_menus(
array(
'nav_pc' => __( 'Navigationsmenü für PCs' ),
'nav_mobile' => __( 'Navigationsmenü für mobile Endgeräte' )
)
);
}
add_action( 'init', 'register_my_menus' );
How can i solve this Issue? I assigned them both for their positions but either 2 times navbar_mobile shows up or only navbar_mobile shows up. and of course the nav tags are closed below. dont worry about that. navbar_pc only shows up when i remove navbar_mobile.
Thanks in Advance,
Your Alwin :)
CodePudding user response:
you can add this condition for both
if(wp_is_mobile()){
//put the mobile menu code
}else{
// put the desktop menu code
}