Home › Forums › Support › Display off canva menu for logged-in users and normal menu for logged-out users
- This topic has 7 replies, 2 voices, and was last updated 4 years, 9 months ago by Tom.
-
AuthorPosts
-
July 1, 2019 at 6:07 am #945946Andrew
Hi,
I have created a function displaying the right menu depending if the user is logged-in or not and if he’s using mobile or computer. What I would like to achieve for my mobile users is that if the user is logged-in he sees an off canva menu, but if he’s logged out he sees a normal menu.
I believe there’s two ways to achieve this:
1. Set off canva to off and somehow add off canva menu for logged-in users (see line ADD OFF CANVA HERE)
2. Set off canva to mobile only and somehow remove off canva menus for logged-out users (see line REMOVE OFF CANVA HERE)Please see my code below and let me know whether this is achievable or not and if so, which is the easiest way of the two mentioned above (I don’t have any preference here).
// Display right menu depending on logged in, logged out, mobile and desktop function edf_display_right_menu ( $args = '' ) { if ($args['theme_location'] == 'primary') { if( is_user_logged_in() ) { if(wp_is_mobile()) { $args['menu'] = 'MobileLoggedIn'; // <== ADD OFF CANVA HERE } else { $args['menu'] = 'DesktopLoggedIn'; } } else { $args['menu'] = 'LoggedOut'; // <== REMOVE OFF CANVA HERE } } return $args; } add_filter( 'wp_nav_menu_args', 'edf_display_right_menu' );
Thanks for your help
Best regards,July 1, 2019 at 9:26 am #946252TomLead DeveloperLead DeveloperHi there,
This might be possible with CSS. Set the Off Canvas Panel to mobile only, then try this:
body:not(.logged-in) #generate-slideout-menu, body:not(.logged-in) .slideout-overlay { display: none; } body:not(.logged-in).slideout-mobile .main-navigation.toggled .main-nav > ul { display: block !important; }
July 1, 2019 at 1:05 pm #946436AndrewHi Tom,
Thanks for your input.
I’ve tested several ways with the CSS code you’ve provided (with and without a menu set as off canva) and unfortunately it’s not quite working.It always shows the same type of menu whether you’re connected or not (either both are off canva, or none is). Would there be another tweak that would do the trick?
Best regards
July 1, 2019 at 6:37 pm #946589TomLead DeveloperLead DeveloperIs your off canvas panel set to mobile only?
The above should make it so the off canvas panel only displays to logged in users. If you’re not logged in, the regular mobile menu should show.
July 2, 2019 at 8:43 am #947126AndrewHi Tom,
Yes it is set to mobile only and doesn’t work.
This is my current setup:Off Canva
Off Canvas Panel: Mobile only
Style: Overlay
Menu Item Height: emptyMenu
Off Canvas Menu set to MobileLoggedInCSS
body:not(.is-user-logged-in) #generate-slideout-menu, body:not(.is-user-logged-in) .slideout-overlay { display: none; } body:not(.is-user-logged-in).slideout-mobile .main-navigation.toggled .main-nav > ul { display: block !important; }
Is there anything I’m doing wrong?
Thanks again for your help
July 2, 2019 at 9:58 am #947201TomLead DeveloperLead DeveloperJuly 2, 2019 at 11:09 am #947286AndrewHi Tom,
You made my day ๐
Working perfectly this time, thank you so much!July 2, 2019 at 3:44 pm #947459TomLead DeveloperLead DeveloperYou’re welcome ๐
-
AuthorPosts
- You must be logged in to reply to this topic.