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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} ); |
This fixed the problem for me. Hope it helps you too!