Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WordPress replaces the excerpt of a password-protected post with “There is no excerpt because this is a protected post.” To show a custom teaser instead, use the the_excerpt filter in a small custom plugin. To let visitors enter the password directly from an archive or listing, return WordPress’s password form in that filtered excerpt. Either option appears only if the active template actually displays excerpts.

Choose what visitors should see

Approach Visitor experience Best fit
Custom excerpt or message Visitors see your teaser or explanation in the listing and must open the post to enter its password. You want to describe the protected post without placing the password form in the listing.
Password form in the excerpt Visitors can enter the password from the listing page. You want the listing itself to provide an unlock step.

WordPress’s password-protection documentation describes protected content as requiring a password to view; this is distinct from setting a post or page to Private.

Show a custom excerpt or message

WordPress’s documentation for password-protected posts uses the the_excerpt filter and post_password_required() to replace the default protected-post message. Put the callback in a custom plugin file rather than editing WordPress core or your theme, so a theme update does not overwrite the customization.

  1. Create a PHP file for your custom plugin, with a valid plugin header, and place it in your site’s wp-content/plugins directory.
  2. Add this callback to the file, then activate the plugin in the WordPress admin area under Plugins:
<?php
/**
 * Plugin Name: Protected Post Excerpt
 */
function freedom251_protected_post_excerpt( $excerpt ) {
    if ( post_password_required() ) {
        return '<p>This post is password-protected. Open it and enter the password to read more.</p>';
    }

    return $excerpt;
}
add_filter( 'the_excerpt', 'freedom251_protected_post_excerpt' );

Replace the sample paragraph with the message or teaser you want. The filter’s return value is the excerpt output; do not print the message from the callback. WordPress permits HTML in the replacement excerpt.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use this as a public teaser only if you are comfortable making its text visible. Password protection does not automatically hide data that a theme or plugin outputs from custom fields. If a custom-field value should remain private, check post_password_required() before rendering it too.

Put the password form in the listing

If you want visitors to unlock the post without first opening it, return the form generated by WordPress. Its developer reference confirms that get_the_password_form() returns the form HTML for a protected post.

function freedom251_protected_post_excerpt_form( $excerpt ) {
    if ( post_password_required() ) {
        return get_the_password_form();
    }

    return $excerpt;
}
add_filter( 'the_excerpt', 'freedom251_protected_post_excerpt_form' );

Add this callback to your custom plugin file in place of the custom-message callback if you want the form rather than a teaser. The function uses WordPress’s default form and respects customizations to that form. The documentation’s guidance for a custom password form says to preserve a maximum field length of 20 characters; WordPress saves only the first 20 because of database constraints.

Check that your template displays excerpts

The filter changes excerpt output, but it cannot make a template display an excerpt where none is rendered. WordPress’s Excerpt block documentation describes the block as a way to show a post excerpt, primarily inside a Query Loop. Check the template used by the relevant home, archive, or Query Loop listing and add or enable an excerpt display if needed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Test the listing while signed out or in a private browser window, so you see the same protected-post behavior as a visitor without the password.
  • If the default message still appears, confirm that the active template uses excerpt output and that the custom plugin is active.
  • If the listing shows no excerpt at all, the template may be showing only a title, featured image, or other post fields; adjust the template rather than changing the filter again.
  • If the form appears in the single-post view but not the archive, check the archive’s template separately. Themes and block templates can render different post fields in different contexts.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use a plugin setting instead of code

If you prefer a settings-based route, the WordPress.org listing for PPWP – Password Protect Pages advertises an option to show excerpts of password-protected content. Review the plugin’s current settings and compatibility with your site before relying on it; the listing does not establish that every theme or configuration behaves the same way.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.