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

Why WORDPRESS is better?

You might have started your own online business. Well, to make it work, you need to own a site. However, if you do not know much about programming languages, then it would benefit you a lot to make use of the simple and easy ones. In this matter, it would be a very good idea […]

The Real Cost of “Just One More Plugin”: A WordPress Bloat Audit

Plugin count is a bad proxy for plugin cost. Here’s a category-based audit that finds real performance savings a “delete unused plugins” tip misses entirely.

How to Transfer From Blogger to WordPress In 6 Super Easy Steps

Blogger is a great tool for beginners, but once a blogger starts to realise the perks of having full control over their content, then WordPress becomes the next best option. There is a lot of information about how to migrate your blog or site. The hardest part about this move is trying to find and […]