Creating ‘Members Only’ Content

in WordPress Tutorials

These days money can be generated by just about everything, including online content and information. But in order to generate money from online content such as certain blog posts and features you need to separate non paying users from the paying users or site members.

Yes, we did go there. The ‘Members Only’ jacket, remember those? Who didn’t love the 80’s? But we digress…

Of course the initial step would be to set up a user login panel or member registration application using either WordPress plugins or native code. As the native code process is quite extensive we are going to recommend two of the best plugins for implementing a user login base; Sidebar Login and Register Plus. For more specific information on the Register Plus plugin please visit our related article.

If you haven’t already setup a user login or members panel please do so before continuing, as the following content would have no use to you otherwise.

Also, as the standard cookie cutter response- we will be editing important source files within your WordPress install so make sure to make a complete database backup for safety precautions.

Displaying Public Content

Unfortunately no matter how many members have subscribed to your WordPress site or blog the most traffic to and from your site will always be public users or visitors. In that case, the idea is to display enough information and content to entice public visitors to signup and login. The better the preview content, the more potential users any exclusive site will have.

The following code segment must be added into your active themes “functions.php” source file (it can be added anywhere so long as it doesn’t break existing code tags):

add_shortcode( 'visitor', 'visitor_check_shortcode' );
function visitor_check_shortcode( $atts, $content = null ) {
	 if ( ( !is_user_logged_in() && !is_null( $content ) ) || is_feed() )
		return $content;
	return 'Display custom lockout message here';

The above code identifies a certain user titled the “visitor” that has not passed a login check, and also defines how the WordPress application should treat public visitors. But in order to define, or segregate, what content displays to public visitors the following code should be added into the related post:

This content is freely available to the public.

The code above will ensure all visitors and members have the option to experience some of what your WordPress blog or site has to offer. But lets be honest, you’re really here to exclude non registered users and provide your members with exclusive content; so lets get to it.

Displaying ‘Members Only’ Content

Now the juicy part!

The related code below will implement a feature that hides all exclusive content and information from users who are not logged in, as well as your feed. Make sure to add it to your active themes “functions.php” source file as you did with the public content code.

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 'Display custom lockout message here';

The above code uses the same method as the ‘public content’ code to check the current user’s status and either deny or allow access to the content accordingly. But as with the alternate segment of code the ‘members only’ feature requires the admin or post author to define what content is for logged in or registered users only. To define ‘members only’ content the following tags need to be implemented in the related post:

This content is for 'members only'!

Thats it! Now your blog should have both a public visitor content section and an exclusive ‘members only’ content section.

Customize The Display Message

Obviously the above code (in both segments) is set to output a message to users if certain conditions are met. For example if a public visitor tries to access ‘members only’ content they will get the following error message:

"Display custom lockout message here"

We definitely don’t want our public visitors seeing the message above, as most would become quite confused and disorderly. In order to customize or change the message displayed simply replace the entire segment after the “return” tag, with the message of your choice. Make sure to include the phrase or message inside the single quotation marks as these are what denote the starting and stopping points of the message.

For a quick example, lets say you want to display the following message to public visitors attempting to access ‘members only’ content; “We’re Sorry. This content is only available for our registered users.”

Then you would simply change the code for the ‘members only’ content to the following:

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 'We're Sorry. This content is only available for our registered users.';

Notice how we only changed the custom content message.

Go Forth and Make Money

Now that we have further bestowed our knowledge on creating ‘members only’ content it is up to you to create an enticing and warranted environment for your registered users. Remember, as we mentioned above, not to forget the public visitors along the way- as some of them may even become paying members at a later time. Use well fashioned advertising features and marketing techniques to rope in that paying user base.

And speaking of fashion may we suggest designing a snazzy jacket line dedicated to your ‘members only’?

Comments (2)

  • Comment by Kevin Muldoon
    Kevin Muldoon

    Did you make sure the code was added within the php tags i.e. placing this code within HTML tags would cause problems.

  • Comment by Shane S
    Shane S

    Sidebar login was a great addition, thanks.

    However when i added the code into my functions.php – it broke my website. I had to reload my theme’s function.php file via FTP. Not good.