Site logo

Archived topic

Page Header Display Diffrent Text for Logged Out User

7 replies · Started by Mike on June 28, 2018

Viewing posts 1–8 of 8

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,
Mike

Hi 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]

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,
Mike

Hi 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.

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,
Mike

Glad 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 ;)

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,
Mike

Good to hear you're enjoying GP. Thanks for the feedback.

This archived topic is closed to new replies.