Need to display the summary of a protected article on WordPress?

Did you know that you can protect items from your blog with a password? By default, WordPress does not display any content for posts with protected content. However, there are several ways to protect an article while viewing a small summary or extract.

In this tutorial, we'll show you how to display a summary or excerpt for a protected post on WordPress.

display the summary of a protected article

Method One: How to manually display an excerpt from a protected article

The first thing you need to do is copy and paste this code snippet into your child theme's functions.php file or a WordPress Plugin specific to the website.

function wpb_protected_excerpt ($ excerpt) {if (post_password_required ()) {$ post = get_post (); $ excerpt = $ post-> post_excerpt; } return $ excerpt; } add_filter ('the_excerpt', 'wpb_protected_excerpt'); function wpb_protected_excerpt_posts ($ content) {if (post_password_required () && is_single ()) {$ post = get_post (); return $ post-> post_excerpt. $ content; }} add_filter ('the_content', 'wpb_protected_excerpt_posts', 10);

Now go to the Article tab on the sidebar, scroll down to the Snippet section and click on the little arrow. You will see an available meta box. This is where you can enter your summary.


Before you publish your article, make sure it is protected. Now you can go to your website and you will be able to view a snippet of the copyrighted articles.

protected-post

2 Method: Using a plugin

Using a password on articles is easy, but it doesn't give you the control you need to make sure that article access is restricted to the right people.

If you have a multi-author blog or want to open registrations on your blog, then using a plugin to restrict access to articles is definitely a better option.

See also our guide on How to create a login page on WordPress

This allows you to control which user has access to protected articles and you can easily control what content you want to offer to your users. Think of it as a member's area with multiple levels of access.

The first thing to do is therefore to install and activate the plugin " Restrict Content Pro“, which is obviously a premium plugin. After installation and activation, you need to visit the following location “ Restrict> Settings“, To configure the plugin.

restrictedcontentmessage

You will need to provide a message to users who do not have permission to view the content. Once it's done, you need to save your settings.

Now, or you can create an article or modify an already existing one that you want to protect. You just need to add the content you want to protect in the shortcode pair " [restrict]… [/ restrict]"

restrictcontentshortcode

Important: You don't need to protect the item from the meta box "Publish".

You can also display an excerpt to users that will be displayed for all users, using the meta box " Restrict This Content Situated lower down. Check the box " Show Excerpt And choose the role that has access to the content.

Discover also our 9 WordPress plugins to create a member space

By choosing the role "Subscriber", then all users on your site will be able to see the content of the article. Those who are not logged in will see the extract only.

subscriberonly

How to sell your premium content on your blog

Restrict Content Pro offers a feature that allows you to sell your content to website members. You can accept payments from Stribe, PayPal and BrainTree.

restrictcontentpayments

You can create subscription packs for users that they can choose from during registration. You can decide what content users will be able to view with their subscription level. You also have the possibility to create a multitude of subscriptions.

Recommended Resources

Discover more resources recommendations that will accompany you in the creation and management of your website.

Conclusion

Here ! That's it for this tutorial. I hope it will be of great use to you. Do not hesitate to share with your friends on your favorite social networks

However, you will also be able to consult our resources, if you need more elements to carry out your projects of creation of Internet sites, by consulting our guide on the WordPress blog creation.

And if you have any suggestions or remarks, leave them in our section Comments.