[Support request] Page Header Display Diffrent Text for Logged Out User

Home Forums Support [Support request] Page Header Display Diffrent Text for Logged Out User

Home Forums Support Page Header Display Diffrent Text for Logged Out User

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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,
    Mike

    GeneratePress 2.1.2
    GP Premium 1.6.2
    #611060
    David
    Staff
    Customer Support

    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]
    #611072
    Mike

    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

    #611081
    David
    Staff
    Customer Support

    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.

    #611680
    Mike

    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

    #611732
    David
    Staff
    Customer Support

    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 ๐Ÿ˜‰

    #611754
    Mike

    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

    #611766
    David
    Staff
    Customer Support

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

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.