Family Encyclopedia >> Electronics

How to display an excerpt from a password protected post in WordPress

Did you know that you can password protect your WordPress posts? By default, WordPress does not display the content of a protected post to users unless a password is entered. However, there are a couple of ways you can password protect posts while still showing a teaser or excerpt. In this article, we will show you how to display the excerpt of a password protected post in WordPress.

How to display an excerpt from a password protected post in WordPress

Method 1:Manually display the excerpt of a protected post

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

 función wpb_protected_excerpt ($ extracto) if (post_password_required ()) $ post = get_post (); $ excerpt = $ post-> post_excerpt; devuelve $ extracto; add_filter ('the_excerpt', 'wpb_protected_excerpt'); función wpb_protected_excerpt_posts ($ content) if (post_password_required () && is_single ()) $ post = get_post (); devolver $ post-> post_excerpt. $ content; add_filter ('the_content', 'wpb_protected_excerpt_posts', 10); 

Now go to the WordPress Posts screen to edit your password protected post and click the screen options button at the top of the page. This will reveal a menu with a bunch of options. You need to make sure that the checkbox next to the statement is checked.

How to display an excerpt from a password protected post in WordPress

This will display the excerpt metadata box below the post editor. You can enter the excerpt of your publication in this box.

How to display an excerpt from a password protected post in WordPress

Before publishing your post, make sure it is password protected. Now you can visit your website and you will be able to see the password protected post excerpt in WordPress.

How to display an excerpt from a password protected post in WordPress

Method 2:Use a plugin to restrict content

Using password-protected posts is easier, but it doesn't give you the control you need to make sure the right users have access to the post.

If you run a multi-user WordPress site, or are willing to open your site to sign up, then using a plugin to restrict access to posts is a much better option.

It allows you to control which users have access to your protected posts and you can easily control how much content you want to show to other users. Think of it like a membership site with multiple subscription levels.

The first thing you need to do is install and activate the Restrict Content Pro plugin. Upon activation, you need to visit Restrict »Settings to configure the plugin.

How to display an excerpt from a password protected post in WordPress

You'll need to provide the message that users will see when they don't have permission to view protected content. Once you're done, simply click the Save Changes button to store your settings.

You can now create a new post or edit an existing post that you want to protect. Simply add the content you want to display as an excerpt in the post content area, and then wrap the rest of the content you want to hide in [restringir] [/ restringir] labels.

How to display an excerpt from a password protected post in WordPress

Important :It is not necessary to make a password protected entry from the post menu.

You can also display an excerpt to all users and give access only to registered users, by using the Content Restriction box below the post editor. Simply check the box next to the statement and choose a user role.

Choosing a subscriber user role will allow all registered users on your site to see the publication when they are logged in. Users who are not logged in will be able to view only the statement.

How to display an excerpt from a password protected post in WordPress

Selling premium content on your site

Restrict Pro Content also allows you to sell memberships for premium content. You can accept payments using Stripe, PayPal, and Braintree.

How to display an excerpt from a password protected post in WordPress

You can create subscription packages for users that they can choose when registering on your site. You can decide what content users will be able to access for their subscription level. You can also have multiple subscription levels.

For detailed instructions, see our guide on how to restrict content to logged in WordPress users.

We hope this article helped you to display excerpt from password protected posts in WordPress. You can also see our list of 40 useful tools to manage and grow your WordPress blog.

If you enjoyed this article, please subscribe to our WordPress YouTube Channel video tutorials. You can also find us on Twitter and Facebook.