• Skip to main content
  • Skip to primary sidebar
  • About
  • Contact
  • Resources
  • Blog
    • Easy Digital Downloads
    • General
    • Genesis Framework
    • jQuery/JavaScript
    • Project Management
    • WordPress Functions
    • WordPress Plugin Development
  • Army Lessons

Scott DeLuzio

WordPress Development Tutorials

Hide Content For Logged Out Visitors

December 13, 2016 Scott DeLuzio Leave a Comment

Sometimes you want to hide certain information on your site unless the visitor is logged in. Maybe you have “member only” content, or perhaps you want to personalize the visitor’s experience on your site (“Hello _____”). Whatever the reason it is easy to hide content for logged out visitors.

This code snippet will create a shortcode [hide_me] that you can use in your WordPress pages, posts, Custom Post Types, widgets, or anywhere shortcodes can be run. Copy and paste it into your theme’s functions.php file or in a custom plugin.

1
2
3
4
5
6
7
8
function sd_hidden_content( $atts, $content = null ) {
	if ( !is_user_logged_in() ) {
		return false;
	} else {
		return $content;
	}
}
add_shortcode( 'hide_me', 'sd_hidden_content' );

function sd_hidden_content( $atts, $content = null ) { if ( !is_user_logged_in() ) { return false; } else { return $content; } } add_shortcode( 'hide_me', 'sd_hidden_content' );

You would use this shortcode on a page like this:

This is some content that should be visible to everyone.
[hide_me]This is some content that should only be visible to logged in visitors.[/hide_me]

This is some content that should be visible to everyone. [hide_me]This is some content that should only be visible to logged in visitors.[/hide_me]

The shortcode can be used multiple times on a page, so it’s easy to hide different content blocks that may be separated by “public” content throughout the page just by repeating the same process shown above.

This is some content that should be visible to everyone.
[hide_me]This is some content that should only be visible to logged in visitors.[/hide_me]
This is some more content that should be visible to everyone.
[hide_me]This is some more content that should only be visible to logged in visitors.[/hide_me]

This is some content that should be visible to everyone. [hide_me]This is some content that should only be visible to logged in visitors.[/hide_me] This is some more content that should be visible to everyone. [hide_me]This is some more content that should only be visible to logged in visitors.[/hide_me]

You can change the hide_me shortcode to whatever you want, by editing the hide_me portion of the code on line 8 above.

WordPress Plugin Development

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Come say hi!

  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube

Tweets by scottdeluzio

My Products

Conditional Checkout FieldsFull Screen Background ImagesQuick CheckoutWP1099

I use affiliate links throughout this site and may earn a commission if you purchase through my links. I do not link to products or services that I do not trust, or use myself.
© 2025 · Scott DeLuzio · Built on the Genesis Framework