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

Easy Tips for Changing the Author of a Published Post in WordPress

Suppose you wrote a post and published it then realized that you are not the author listed, how will you plan to change the “author”? There are other reasons why writers need to change the author of the blog posts such as: when you need to replace the author name under your name, as well […]

Exclude the category you don’t need from your menu

Every time you add a new theme to your WordPress blog and you find that this theme show all your categories in a menu. The idea of excluding a category from the menu come directly to your mind. Today I propose to change the categories menu you have in your home page to suit your […]

What’s New In WordPress 4.3

  WordPress is the most widely used content management system in the world. It is an excellent platform for beginners to launch their blog without needing expert knowledge on HTML. WordPress is also useful for sole proprietors who want their business to have an online presence but at the same time do not want to […]

WordPress.com Guidelines: A Hands-On Test of the New AI Content Memory Feature

I tested WordPress.com’s new Guidelines feature firsthand: what it actually does, what it doesn’t, and whether AI writing tools really follow the rules you set.