Can I show content to only someone NOT logged into WordPress?

We have a lot of shortcodes for PilotPress that allow us to show content based on the person's membership level, if they have a certain tag or not, etc., but is there a way to show something ONLY to someone who is not logged in? I'd like to have a page that shows someone who is a guest a link to register for my site, but hide that link from anyone already logged in.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

While we don't out-of-the-box have a shortcode for this, I compiled some instructions on how to easily add one to your theme.

You can reference this article which was where I found the instructions, but I broke it down to some easy to follow steps with screenshots below:

Step 1. Copy this code:

add_shortcode('GUEST','show_guest_content'); function show_guest_content($atts,$content){ if (!is_user_logged_in()){ return $content; } return ''; }

Step 2. Paste this code into the bottom of your functions.php WordPress theme file. You can get there by going to Appearance > Editor > Theme Functions (which will be listed on the right of the Editor page). Here is a screenshot of what that should look like for you when you get it in there. Be sure to save it when you're done!

Step 3. Reference your new shortcode by surrounding content with it like this: 

[GUEST]content here[/GUEST]. See screenshot of what that will look like in your page editor.

As always, this should only be done by someone comfortable with editing the theme files. Make a backup of your theme in case something goes wrong. If the theme becomes inoperative because of an error in coding you'll have to log in via FTP or a control panel file manager and either restore the functions.php file or delete your theme (in which case WordPress will load the default theme).

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-06-10 08:04:06 -0700

Seen: 32 times

Last updated: Jun 10 '16