Introduction
WordPress allows you to have password protected posts or pages.
This means that only the users which have the password you set up for that post/page will be able to see the content.
That is a cool feature.
But sometimes, you might want to change the default password protected message in WordPress.
How to make a post/page password protected in WordPress
First of all, let's see how can you make a post or page to be protected by a password.
This is actually very eazy to do in WP.
When you edit the page or post in your WP Dashboard, you just need to click on "Visibility" on right sidebar under "Status & visibility", choose "Password Protected" and add your desired password:
When someone visits the post/page, will see something like this:
How to change the default message on the password protected post/page in WP
If you want to change the message on the protected post/page you need to add the below PHP code to your functions.php
file in your theme folder:
add_filter('the_password_form', 'zi_change_default_message');
function zi_change_default_message ($output) {
$default_text = 'To view this protected post, enter the password below:';
$new_text = 'This is my secret. You need a password to see it.';
$output = str_replace($default_text, $new_text, $output);
return $output;
}
After you add the above PHP code to your functions.php
file and all it is uploaded to your FTP/SFTP, the post/page will look like this:
How to HIDE the default message on the password protected post/page in WP
If you want to hide the message, you will use almost the same code as above, but for the $new_text variable you will just have an empty string:
add_filter('the_password_form', 'zi_change_default_message');
function zi_change_default_message ($output) {
$default_text = 'To view this protected post, enter the password below:';
$new_text = ' ';
$output = str_replace($default_text, $new_text, $output);
return $output;
}
Conclusion
I really hope that you will find these solutions really easy to be added to your WP website. Hiding or changing that default message in WP it is really easy and it can be done without using a plugin.
Comments closed
Please contact me, if you have any questions or suggestions.