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

Don’t lose your visitors when your database is unavailable

When your WordPress blog has trouble connecting with the database, it returns a nice “Error Establishing a database connection”. Instead of losing visitors, db-error.php might be the useful solution. You should create and place it in the wp-content folder. After that paste this short code in it. [sourcecode language=”php”]<?php // db-error.php $host=$_SERVER[‘HTTP_HOST’]; $uri=urlencode($_SERVER[‘REQUEST_URI’]); header("Location: http://google.com/search?q=cache:$host$uri&quot;); […]

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

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