- This topic has 7 replies, 2 voices, and was last updated 7 years, 9 months ago by
David.
-
AuthorPosts
-
June 28, 2018 at 1:45 pm #611010
Mike
Hello,
I am looking for a way in my page header to be able to display a specific piece of text for logged out users and something diffrent for logged in users.
I am using this on the woo commerce my account page, and I wish for logged in users to be presented with the standard page name “My Account” and logged out users to be presented with “Login”
Thanks,
MikeJune 28, 2018 at 3:36 pm #611060David
StaffCustomer SupportHi Mike,
we can create a couple of short codes with this snippet:
add_shortcode('USER','show_user_content'); function show_user_content($atts,$content = null){ global $post; if (is_user_logged_in()){ return $content; } return ''; } add_shortcode('GUEST','show_guest_content'); function show_guest_content($atts,$content){ if (!is_user_logged_in()){ return $content; } return ''; }https://docs.generatepress.com/article/adding-php/
Then its just a case of wrapping the content in each of the shortcode names:
[USER]I am logged in[/USER] [GUEST]I am not logged in [/GUEST]June 28, 2018 at 4:01 pm #611072Mike
Hello David,
Can that code all be run from the header text box? I am trying to avoud adding to the functions.php file.
Do you know of a plugin that maybe acheives the same thing?
Thanks,
MikeJune 28, 2018 at 4:19 pm #611081David
StaffCustomer SupportHi Mike,
i would suggest using the Code Snippets plugin to add the snippet provided, a link to it is in the Adding PHP article. It’s the recommended alternative to using a Child theme function file.
June 29, 2018 at 12:49 pm #611680Mike
Hello David,
Sorry for not responding sooner.
I have used the code snippits plugin and its now all working a treat!
Might be a nice feature to allow PHP in the page header box…
Thanks,
MikeJune 29, 2018 at 2:43 pm #611732David
StaffCustomer SupportGlad to hear thats working. I think their are some complexities in doing that. But you’ll be glad to hear that GP 1.7 will have this covered without using code 😉
June 29, 2018 at 3:03 pm #611754Mike
Hello,
That is fantastic! Its like you read my mind! 🙂
Keep up the great work, use and reccomend the pro version of your theme for all my projects.
Love it so much!
Going to sign up to be an affiliate right now!
Thanks,
MikeJune 29, 2018 at 3:28 pm #611766David
StaffCustomer SupportGood to hear you’re enjoying GP. Thanks for the feedback.
-
AuthorPosts
- You must be logged in to reply to this topic.