How to Show Excerpt of a Password Protected Post in WordPress


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.

Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.