Custom Password Protected Message

8 Jul 2022

If you put a post or CPT to password protected, and you want to change the default message, for example you want to put a link with a request the password contact form in the message then use the code below.

// Custom 'Password Protected Message'
add_filter('the_password_form', 'arsh_message');
function arsh_message ($output) {
    $default_text = 'This content is password protected. To view it please enter your password below:';
    $new_text = 'This content is password protected. To get a password Click <a href="/request-password/" style="padding:6px 10px;background-color:#383e42;color:#fff">REQUEST PASSWORD</a> or enter password below if you have already.'; // change this text as your need.
    $output = str_replace($default_text, $new_text, $output);
    return $output;

Was this article helpful?



Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy