WordPress Change Password Form Text

WordPress posts also support password protection. Mean you make a post that needs a password to view the post. This password-protected post-default design and text can change. Let’s we can do it in WordPress Change Password Form Text.

WordPress Change Password Form Text

Go to theme functions file., then write this function:

function my_talk($total_form){   
$total_form = str_replace(“This content is password protected.”, “Password Protected Post.”,$total_form);
return $total_form;}
add_filter(‘the_password_form’,’my_talk’); 

Explanation: When making a post in password-protected format, the default form is showing a little bit odd in WordPress.
It’s showing like this –
This content is password protected. To view it please enter your password below.

wordpress password form text change



If we want to change this text, we just need to use a filter hook called “the_password_form”. But we can not change complete the hook, because the hook also stored the password form, so need to replace the text only.

For changing the text/string, we can use a PHP function called str_replace. str_replace is changing only text. The function can implement like this –

str_replace(‘text need to replace’,’after replacing the text’,’your string’);

If we want to use this, just need to grab the default password form with a variable. We can store it on a variable by passing a variable inside the function. Then function like this:



function my_talk($total_form){
$total_form = str_replace(“This content is password protected.”, “Password Protected Post.”,$total_form);   
return $total_form;}

wordpress password form text

After making the function we need to add it to the filter hook then the hook like this:
add_filter(‘the_password_form’,’my_talk’);

function my_talk($total_form){
    $total_form = str_replace("This content is password protected.", "Password Protected Post.",$total_form);
    return $total_form;
}
add_filter('the_password_form','my_talk');

Another thing that looks odd is when we see that a password-protected post title is formated with WordPress like this:

If we want to change this

we can use protected_title_format hook. Then the function like this:

function zindex_protected_post_title_change(){
return ‘%s’;
}
add_filter(‘protected_title_format’,’zindex_protected_post_title_change’);

function zindex_protected_post_title_change(){
    return '%s';
}
add_filter('protected_title_format','zindex_protected_post_title_change');