Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Show Excerpt of a Password Protected Post in WordPress

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

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.

Showing excerpt for password protected posts

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.

Enabling excerpt meta box on post edit screen in WordPress

This will display the excerpt meta box below the post editor. You can enter your post’s excerpt in this box.

Adding excerpt for your 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 excerpt for the password protected post in WordPress.

Showing excerpt for a 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.

Restricted content settings

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.

Restrict Content shortcode

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.

Allowing only logged in users to view content

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.

Accepting payments for protected content with Restrict Content Pro

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

6 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Kim says

    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 says

      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;
      }

  3. Lori says

    what would the code be for a page? This causes all my pages to be hidden, only header and footer showing.

    • Stefan says

      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! ;- )

  4. Adrienne says

    Not sure if this works now. People think content should be free and accessible…. Maybe for downloads or donations, I think it would work.

Leave a Reply to Lori Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WPBeginner Assistant
How can I help you?

By chatting, you consent to this chat being stored according to our privacy policy and your email will be added to receive weekly WordPress tutorials from WPBeginner.