X

Member only content

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


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 '';
}
[member]
This text will be only displayed to registered users.
[/member]

Comments  Leave a Reply

  1. 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!!

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

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!