Create a 3D Starfish Icon
April 10, 2013 by Yvo
Members only access
Sometimes you only want to show content for registered users. You can think of zip-files with photo’s or other content. To do this in wordpress you can achieve this by following these instructions.
Paste the following code in your functions.php file.
(this file is located in your <root>/wp-content/themes/<your-theme>/ directory)
//register the shortcode in wordpress
add_shortcode( 'registered', 'registered_only_shortcode' );
function registered_only_shortcode( $atts, $content = null )
{
//criteria
//is the user logged in?
//is the content not null?
//isn't it an RSS request?
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
{
//the user matches the criteria... return the content.
return $content;
}
else
{
//the user didn't match one of the criteria above.
//so return nothing.
return '';
}
}
Anytime when you post something with “registered users only”-content you can use it in the following way:
This is my post. Everybody can see it. [registered] You are registered so you can read this! Unregistered user can not see this text. [/registered]
As you can see it is very easy to setup.







Recent Comments