Did you know that you can password protect your WordPress posts? By default, WordPress does not show the contents 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 show excerpt of a password protected post in WordPress.
Method 1: Manually Showing The Excerpt of a Protected Post
First thing you need to do is to copy and paste this code snippet in your child theme‘s functions.php file or a site-specific WordPress plugin.
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 Posts screen in WordPress to edit your password protected post and click on the screen options button on 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 excerpt is checked.
This will display the excerpt meta box below the post editor. You can enter your post’s excerpt in this box.
Before publishing your post make sure it is password protected. Now you can visit your website, and you will be able to see the excerpt for the password protected post in WordPress.
Method 2: Using a Plugin to Restrict Content
Using password protected posts is easier, but it does not give you the control you need to make sure that the right users have the access to the post.
If you run a multi-user WordPress site, or you are willing to open your site for registration, 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 as a membership site with multiple subscription levels.
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.
You will need to provide the message users will see when they do not have the permission to view a protected content. Once you are done simply click on the save changes button to store your settings.
Now you can create a new post or edit an existing post that you want to protect. Simply add the content you want to show as excerpt in the post content area, and then wrap rest of the content that you want to hide between [restrict] [/restrict]
tags.
Important: You don’t need to make a post password protected from the publish menu.
You can also show excerpt to all users and give access to only logged in users, by using the Restrict Content meta box below the post editor. Simply check the box next to excerpt and choose a user role.
Choosing a subscriber user role will allow all registered users on your site to view the post when they are logged in. Non logged in users will be able to see the excerpt only.
Selling Premium Content on Your Site
Restrict Content Pro also allows you to sell memberships for premium content. You can accept payments using Stripe, PayPal, and Braintree.
You can create subscription packages for users which they can choose from 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, please take a look at our guide on how to restrict content to registered users in WordPress.
We hope this article helped you show excerpt for password protected posts in WordPress. You may also want to see our list of 40 useful tools to manage and grow your WordPress blog.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Jiří Vaněk
This is a great and simple solution. I was looking for something within WordPress that would work exactly like Patreon, where I had premium content. It shows a snippet of the article, but the rest is accessible only after entering a password. This solution came in very handy.
Kim
Hello- I went to use your code to Manually Showing The Excerpt of a Protected Post.
It works great up until you put the password in and go to read the protected post- it comes up blank! So the excerpt shows on the category page. I go to the post, put in the password to read the entire thing and it comes up blank, despite there being a written post in the dashboard.
Would appreciate an edit to this almost perfect manual override for excerpts on protected content!
Jeff
Apparently post_password_required returns FALSE if the password has been entered. Thus the original logic fails. This may not be quite correct either, but it’s working for me.
if ( post_password_required() ) {
$post = get_post();
return $post->post_excerpt.$content;
} else {
return $content;
}
Lori
what would the code be for a page? This causes all my pages to be hidden, only header and footer showing.
Stefan
Hi Lori,
I have the same problem. Have you found a solutions for this problem?
Of course anybody else is also invited to share help and iformation! ;- )
Adrienne
Not sure if this works now. People think content should be free and accessible…. Maybe for downloads or donations, I think it would work.