If you use password-protected posts for premium content or members-only areas, you might’ve noticed something frustrating: WordPress hides these posts from your blog feed and archive pages.
This means that visitors have no idea what valuable content is waiting behind the password wall. And that can make it harder to get sign-ups or keep people interested. 😕
The good news is, you can show a short preview (or excerpt) of your protected posts. It gives people a sneak peek at what they’re missing, without giving away the full content.
After trying different methods, we found the easiest way to do this is with WPCode. In this guide, we’ll show you step by step how to display excerpts of password-protected posts without breaking your WordPress site.

Why Show the Excerpt of Password-Protected Posts?
Sometimes, completely hiding password-protected posts can feel like putting up a wall that could turn visitors away. If they can’t see what they’re missing, they might not feel motivated to unlock the content. That’s where an excerpt can help you!
Showing an excerpt gives readers a sneak peek of what’s inside. It’s like sharing the first chapter of a book: it sparks curiosity and makes them want more.
Whether it’s premium content, an exclusive video, or a members-only guide, a preview can be just the nudge someone needs to sign up, log in, or enter a password.
This is especially helpful for businesses or creators who offer memberships. A well-crafted excerpt showcases the value of your content and strengthens trust with your audience by showing them exactly what they’re signing up for.
It’s also helpful in simpler cases, like sharing personal content with family and friends using password protection.
In the end, it’s about finding the balance between keeping your content secure and making it enticing enough for visitors to engage with it. Showing excerpts is a simple way to do just that.

Do note that the ‘Add an excerpt…’ option is always available in the WordPress editor.
However, for password-protected posts, the excerpts won’t show up unless you add a custom code snippet to make them visible.
With that in mind, we’ll show you how to show excerpts of password-protected posts using a custom code plugin. Here’s a quick overview of all the steps we’ll cover in this guide:
- Step 1: Installing a WordPress Code Snippet Plugin
- Step 2: Adding a Custom Snippet for Showing Excerpts
- Step 3: Inserting the Post Excerpt Using the Block Editor
- Bonus Tip: Selling Premium Content and Creating a Paywall
- FAQs: Showing Excerpts for Password-Protected WordPress Posts
- More Ways to Control Access and Grow Your WordPress Website
Ready? Let’s get started!
Step 1: Installing a WordPress Code Snippet Plugin
Typically, people will tell you to add a custom code snippet to your theme’sfunctions.php
file or a site-specific WordPress plugin.
However, this method is not very beginner-friendly. One tiny mistake, and you risk breaking your WordPress site altogether.
This is why we always recommend using a code snippet plugin, and our favorite is WPCode. Across our partner brands’ sites, we use WPCode to add and manage custom code snippets, so we know firsthand how powerful yet easy-to-use it can be.
For details about the plugin, you can check out our complete WPCode review.

To add custom code snippets, you can use the free version of WPCode. However, upgrading to WPCode Pro will unlock a lot more features, like viewing the full revision history for all your snippets and scheduling your code.
For this tutorial, we’ll use the free version of WPCode.
So, let’s install and activate the WPCode plugin. If you need help, then you can see our guide on how to install a WordPress plugin.
Upon activation, you can navigate to Code Snippet » + Add Snippet. Then, you’ll want to hover over the ‘Add Your Custom Code (New Snippet)’ and click the ‘+ Add Custom Snippet’ button.

On the next screen, you’ll need to select the code type for your custom code snippet.
You can click on ‘PHP Snippet.’

This will take you to the WPCode code snippet editor.
From here, you can add the name for your snippet. This is for your reference only, but you might still want to use something clear so you can easily refer back to it later.
For example, we named ours ‘Show Excerpt of a Password-Protected Post.’

With that done, you can move on to the next step.
Step 2: Adding a Custom Snippet for Showing Excerpts
In this step, you’ll need to copy and paste the following code snippet into the WPCode ‘Code Preview’ field:
function wpb_protected_excerpt($excerpt) {
if (post_password_required()) {
$post = get_post();
if (!empty($post->post_excerpt)) {
return '<p>' . esc_html($post->post_excerpt) . '</p>';
}
}
return $excerpt;
}
add_filter('the_excerpt', 'wpb_protected_excerpt');
function wpb_protected_excerpt_posts($content) {
if (post_password_required() && is_single()) {
$post = get_post();
if (!empty($post->post_excerpt)) {
return '<p>' . esc_html($post->post_excerpt) . '</p>' . $content;
}
}
return $content;
}
add_filter('the_content', 'wpb_protected_excerpt_posts', 10);
Here’s what it might look like in the interface:

Then, simply toggle the switch from ‘Inactive’ to ‘Active.’
After that, go ahead and click the ‘Save Snippet’ button.

Step 3: Inserting the Post Excerpt Using the Block Editor
Now that the custom code snippet is activated on your site, you can open a post and add your excerpts.
Before everything else, make sure your post is password-protected. If you haven’t done so, you can find the setting in the ‘Status’ section.
In our case, we’ll click the ‘Published’ status link.

Then, simply check the ‘Password protected’ option.
After that, you can add the password to the respective field.

Once you do that, you can close the popup by clicking anywhere in the content editor outside the popup.
The next step is adding the post excerpt. To make it easy, you can simply copy the opening lines of your blog post.
🧑💻 Pro Tip: WordPress doesn’t set a hard limit for how many characters you can add in the ‘Excerpt’ field. However, the way excerpts show up on your site depends on your theme or widget settings – they might cut off longer excerpts to fit the design.
We recommend keeping excerpts to about 55 words. But it’s a good idea to check how your excerpts look on your site and tweak them to match your style!
You’ll then click the ‘Add an excerpt…’ link, and a popup window where you can add an excerpt will appear.

After pasting your excerpts into the ‘Excerpt’ field, click anywhere outside the popup on the content editor.
You should now be able to see the post excerpt below the ‘Set featured image’ settings.

If anything, you can always tweak your excerpt by clicking the ‘Edit excerpt’ link.
Finally, hit the ‘Update,’ ‘Save,’ or ‘Publish’ button to make the changes live.
Now, you can visit your website and see the excerpt for the password-protected post in WordPress.

Bonus Tip: Selling Premium Content and Creating a Paywall
If you’re looking to monetize your content, then adding a paywall might be a better choice.
A paywall locks your content until readers take specific actions, such as paying for access. It’s an effective way to earn revenue, especially if you want to avoid running ads. You can charge for ongoing subscriptions or offer a one-time fee for lifetime access.

With MemberPress, creating and managing paywalls is simple. It’s one of the best paywall plugins, and we use it ourselves to manage our free video site.
To learn more about the plugin, please see our detailed MemberPress review.
MemberPress lets you set up different subscription packages and decide which content is accessible at each level. This flexibility lets you offer multiple membership tiers tailored to your audience’s needs.
For more details, you can check out our guide on how to create a paywall in WordPress.
💡 Note: Paywalls aren’t always about money. For instance, The New York Times uses them to grow email lists by asking visitors to subscribe to a newsletter or create a free account. Meanwhile, The Washington Post offers trials or free articles before requiring payment.
FAQs: Showing Excerpts for Password-Protected WordPress Posts
Got questions? Below are some common things people ask when setting up password-protected excerpts in WordPress.
Will this method work with any WordPress theme?
Yes, this method will work with any WordPress theme. The code uses a standard WordPress function, known as a filter hook, which isn’t dependent on your specific theme. This means it changes how WordPress works at its core, so it stays compatible across different designs.
Is it safe to add this code using the WPCode plugin?
Absolutely. Using a code snippet plugin like WPCode is the safest way to add custom code to your WordPress site.
It has smart error handling that can stop a bad snippet from breaking your site. Plus, it keeps your code separate from your theme files, so you won’t lose your customizations if you update or switch themes.
Can I also show excerpts for password-protected pages?
Yes, this code works for any post type that supports excerpts, including pages. But you might need to enable excerpts for pages first.
Some themes do this automatically. If yours doesn’t, you can easily turn it on. For step-by-step help, see our guide on how to add excerpts to your pages in WordPress.
What’s the difference between password protection and a membership plugin?
Password protection works well for simple situations, like sharing one post with a small, trusted group. Everyone uses the same password to view the content.
A membership plugin like MemberPress is made for selling access. It lets you create multiple subscription levels, accept payments, and give each user their own login. It’s perfect if you want to build a full membership site or sell online courses.
More Ways to Control Access and Grow Your WordPress Website
We hope this article helped you learn how to show excerpts for password-protected posts in WordPress. Now you have a powerful way to entice readers without giving everything away.
Next, you may want to check out these other guides on controlling content access and growing your site:
- How to Add Content Locking in WordPress
- How to Add a Forum in WordPress
- How to Create Your Private Community with WordPress
- How to Make Your WordPress Blog Completely Private
- How to Hide Password-Protected Posts from Your Blog Page
- Useful Tools to Manage and Grow Your WordPress Blog
- Many Ways to Protect Your Content in WordPress
- Ultimate Guide to Creating a WordPress Membership Site
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.