Hide a part from your content from non-registred visitors

Trying to get new “members” to his WordPress blog is not always easy. To try to push visitors to register and join your blog, you might resort to drastic measures as to conceal a portion of text.
Or, another scenario, you might want to reserve a portion of text only to the most loyal visitors: your members. This can be done without a plugin and even here the solution!

membersonly

First, copy and paste the following code in your functions.php file (which I repeat must be in the file .php on your WordPress theme):

[sourcecode language=”php”]add_shortcode( ‘membre’, ‘member_check_shortcode’ );

function member_check_shortcode( $atts, $content = null )
{
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
return $content;
return ”;
}[/sourcecode]

Now, when you write a new article, add the new tag

[sourcecode language=”php”][Member] [/ member][/sourcecode]

to show the text only to your blog members.

You May Also Like

Fix the ‘Scheduled Maintenance’ Error on WordPress

One of the most annoying error in WordPress is the ‘Scheduled Maintenance’ message a Webmaster gets after an automatic upgrade has completed. This problem is mainly caused by a failed automatic upgrade or an interrupted update process.  So each time a visitor tries to visit your home page, he/she will get the following message: Briefly unavailable […]

Use the RSS feed for a specific category

If you want to encourage your readers to subscribe to some of the updates of your site, it may be interesting to set up RSS feeds by category. The feed url to track updates on a category is obtained very simply by getting the URL of your category and add this /feed after the link they […]

5 Common Mistakes Made by WordPress Beginners

  WordPress is a global platform for beginners to start their own website. It is a free platform without any barriers to entry that allows anyone to start a website with just basic knowledge regarding web development. Since it is an extremely easy to use content management system some beginners make very common mistakes when […]

Why WordPress is the ultimate option for Non-techy business owners

In this digital age, every business needs an online presence. This can become an issue for business owners especially who have a limited budget and cannot afford to hire a digital agency or a web developer. Small business owners take up on this task on their own even if they do not possess the required […]