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

Save more WordPress’ database disk space with a simple trick

If you use WordPress as blogging platform, and you have installed a recent version, you must have see that it has become more greedy in space. This is particularly due to the registration of “revisions”. What is “revisions”? These are versions of posts that are recorded as you write. This is a very useful feature […]

Pressable: The WordPress Hosting Built for Next-Generation Demands

WordPress isn’t your grandfather’s blogging platform anymore. Pressable understands this fundamental shift. While most hosting companies are still optimizing for traditional page rendering, Pressable by Automattic, the team behind WordPress itself, to handle what comes next. Multi-channel content. Headless architectures. API-first patterns. Infrastructure that evolves with the platform, not behind it. The disconnect between what […]

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 […]

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 […]