Home › Forums › Support › Hide item on mobile when logged-in or logged-out This topic has 3 replies, 2 voices, and was last updated 5 years, 4 months ago by Elvin. Viewing 4 posts - 1 through 4 (of 4 total) Author Posts December 7, 2020 at 2:34 pm #1570895 nik9 Hello, We use this function to add a icon in the navigation for mobile devices. However, is there a way to add a CSS class to hide this if a user is logged-in or logged-out? add_action( 'generate_inside_mobile_header','my_account_mobile_menu' ); function my_account_mobile_menu() { ?> <div class="mobile-bar-items"> <a title="My Account" href="/my-account/"><i class="fas fa-user"></i></a> </div> <?php } Cheers December 7, 2020 at 5:16 pm #1570991 ElvinStaff Customer Support Hi, You can modify your PHP snippet to use is_user_logged_in() on a if condition. https://developer.wordpress.org/reference/functions/is_user_logged_in/ Example: add_action( 'generate_inside_mobile_header','my_account_mobile_menu' ); function my_account_mobile_menu() { if( is_user_logged_in() ) { echo = '<div class="mobile-bar-items"> <a title="My Account" href="/my-account/"><i class="fas fa-user"></i></a> </div>'; } } What this does is it only renders the markup on the hook if the user is logged in. Else, it doesn’t do anything. December 7, 2020 at 6:00 pm #1571021 nik9 Hi Elvin, Thanks. But this snipped has a syntax error. Its not possible to save this without a error. 🙁 December 7, 2020 at 6:07 pm #1571025 ElvinStaff Customer Support Ah my bad. I accidentally added = between echo and the markup string. Here’s the one w/o the error: add_action( 'generate_inside_mobile_header','my_account_mobile_menu' ); function my_account_mobile_menu() { if( is_user_logged_in() ) { echo '<div class="mobile-bar-items"> <a title="My Account" href="/my-account/"><i class="fas fa-user"></i></a> </div>'; } } Author Posts Viewing 4 posts - 1 through 4 (of 4 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In