Stefan Ledin

WordPress password protected page: white screen after login

A customer contacted me about an issue where users couldn’t access a password protected page in WordPress. After login, they where met with just a white page. Here’s how I solved it!

Of course, everything worked as expected for me. But after a while, I figured out that users probably where using the URL www.mycustomer.com/secret-page instead of mycustomer.com/secret-page. The solution was to add a hidden input field containing the ”real” permalink.

I used the WordPress filter the_password_form and added the input field by doing a search and replace on the closing form tag.


<?php
add_filter( 'the_password_form', function( $output ) {
$input = '<input type="hidden" name="_wp_http_referer" value="'.get_permalink().'"></form>';
$output = str_replace( '</form>', $input, $output );
return $output;
} );

view raw

functions.php

hosted with ❤ by GitHub

This fixed the problem for me. Hope it helps you too!