Hi, I used the following PHP code to display different menus for Logged in/Not logged in users and it works fine for desktop users.
function my_wp_nav_menu_args( $args = ” ) {
if( is_user_logged_in() ) {
// Logged in menu to display
$args[‘menu’] = 43;
} else {
// Non-logged-in menu to display
$args[‘menu’] = 35;
}
return $args;
}
add_filter( ‘wp_nav_menu_args’, ‘my_wp_nav_menu_args’ );
However, I also want to have different menus for Logged in/Not logged in users on mobile. But I’m stuck at how to achieve this. I’ve been messing around with the code and have come up with the following:
function my_wp_nav_menu_args( $args = ” ) {
if( is_user_logged_in() ) {
// Logged in menu to display
if(is_mobile()) {
$args[‘menu’] = 9;
} else {
$args[‘menu’] = 2;
}
} else {
// Non-logged-in menu to display
$args[‘menu’] = 42;
}
return $args;
}
add_filter( ‘wp_nav_menu_args’, ‘my_wp_nav_menu_args’ );
I’m stuck because I don’t actually know if the “is\_mobile” function is correct, or how to implement the not-logged in mobile check. Any help/advice appreciated.
[ad_2]
What are you trying to achieve with the first else condition?
Assuming it’s unintentional, the conditional statements would look like
`if( is_mobile() ) {`
`$args[‘menu’] = 9;`
`} else {`
`// Non-logged-in menu to display`
`$args[‘menu’] = 42;`
`}`
You’re looking for wp_is_mobile()