I have a Wordpress website with 2 different pages that are protected using the native Wordpress password protect functionality.
I am looking for a way (if one exists) to customize the text above the password field differently for different password-protected pages.
I found a plugin that replaces the default text with custom HTML code, but then this message displays for ALL password protected pages.
What I'm trying to achieve is for password-protected page A to show "Message A" above the password field, and password-protected page B to show "Message B" above the password field, whereas currently all password-protected pages display the same message.
Does anyone know if there is a way to achieve this result? Thanks in advance!
It is possible.
Yo have to add this code to your functions.php :
add_filter( 'the_password_form', 'custom_password_protected_form' );
function custom_password_protected_form($output) {
global $post;
switch ($post->post_name) {
case 'page-a':
$replacement_text = 'Message A';
break;
case 'page-b':
$replacement_text = 'Message B';
case 'default':
$replacement_text = '';
}
if (!empty($replacement_text)) $output = str_replace(__( 'This content is password protected. To view it please enter your password below:' ), $replacement_text, $output);
return $output;
}
Tested on WP 5.2.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With