wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Member only content

wordpress snippet

Adding this PHP code to the functions.php file of your wordpress theme will allow you to place content you only wish members to see within the members short code [member][/member].

snippet :  copy
add_shortcode( 'member', 'member_check_shortcode' );
function member_check_shortcode( $atts, $content = null ) {
	 if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
		return $content;
	return '';
source →
snippet :  copy
This text will be only displayed to registered users.
source →

Did you like this post? If so please share it with your friends. Thanks!

  • EarthShaver

    Sweet Snippet!!
    but leaving the space empty for non-member visitors would be too boring. how about inserting some text-message for non-member visitors, like “You must be logged in to view this content” or something like that?

    Oh, and thanks for the good work!!

    • http://wpsnipp.com Kevin Chard

      just return something other within return ‘some text'; and not blank should do the trick.