Support #14074


page password protection problem

Added by Marilyn Weber almost 3 years ago. Updated 9 months ago.

Priority name:
Category name:
WordPress (misc)
Target version:
Start date:
Due date:
% Done:


Estimated time:
Deployment actions:


Ines Vano_Garcia has successfully password protected the "readings and other material" page on her site,

However, her attempt and mine to do so for a different page do not work - the link for "blogging",

She appears to have done the same thing on each page. I tried too, but no luck. Is this a bug?


Actions #1

Updated by Boone Gorges over 2 years ago

  • Category name set to WordPress (misc)
  • Status changed from New to Reporter Feedback
  • Target version set to Not tracked is a special kind of page, which has been selected as the 'Posts page' at When configured this way, WordPress no longer uses the regular "single page" template to generate the page, but instead uses the "post archive" template. The post-archive template does not support password-protection in the same way as the single-page template; on archives, the content of individual password-protected posts will be hidden, but the entire archive cannot be hidden. This is a limitation of the WordPress platform.

If it's important that specific posts be hidden behind a password, then each of those posts must be password-protected separately (such as, for example). You cannot password-protect the "archive" or "Blogging" page as a shortcut.

I'm adding Ray and Jeremy as watchers in case they know of any shortcuts or other ways around this issue.

Actions #2

Updated by Marilyn Weber over 2 years ago

thanks - this is super useful to know full stop. I'll pass it on to Ines.

Actions #3

Updated by Raymond Hoh over 2 years ago

Boone, the following would allow password protection on the blog page (a.k.a Posts page):

add_action( 'parse_query', function( $q ) {
    // Bail if not main query or blog page.
    if ( ! $q->is_main_query() || ! $q->is_home() ) {

    // Get blog page ID.
    $id = $q->get_queried_object_id();

    // Bail if blog page is not password protected.
    if ( ! post_password_required( $id ) ) {

    // If password protected, wipe out posts and show password form.
    add_action( 'loop_start', 'cac_blogpage_postpass_ob_start', -9999 );
    add_action( 'loop_end', 'cac_blogpage_postpass_ob_end_clean', 999 );
    add_action( 'loop_end', function() use ( $id ) {
        echo get_the_password_form( $id );
    }, 9999 );
} );

function cac_blogpage_postpass_ob_start( $q ) {
    // Sanity check.
    if ( ! $q->is_main_query() ) {

    remove_action( 'loop_start', __FUNCTION__, -9999 );

function cac_blogpage_postpass_ob_end_clean( $q ) {
    // Sanity check.
    if ( ! $q->is_main_query() ) {

    remove_action( 'loop_end', __FUNCTION__, 999 );
Actions #4

Updated by Boone Gorges over 2 years ago

Thanks, Ray! This is very clever. I worry about weird edge cases, though - like when a theme doesn't properly implement the loop, so that loop_start and loop_end hooks aren't fired as expected. It also raises the possibility of weird display issues, because WP's default behavior is to swap out the_content with the password form, which might have different markup as a wrapper than the post loop.

More generally, I am wary of doing magic like this, especially as regards privacy. It feels fragile. And it gives the incorrect indication that hiding an archive page means hiding the individual items on that archive, which is definitely not the case - even with this trick in place, you'd have to hide individual pages as well if you didn't want them accessible via their URLs (or via other, non-blocked archives like the date archives). So it provides a sense of false security.

For these reasons, I recommend against implementing any further changes of this sort.

Actions #5

Updated by Marilyn Weber 9 months ago

Feel free to close this

Actions #6

Updated by Boone Gorges 9 months ago

  • Status changed from Reporter Feedback to Abandoned

Also available in: Atom PDF