2014-03-19 #wordpress

Change The Password Protected Text In WordPress

One of the features that I've found content editors find really useful is the password protected pages in WordPress. This is a built in feature that you can use directly from the edit page. To set a password on a page you need to find the publish meta box on the edit post screen, under the visibility menu you will see the password protected textbox. All you have to do is enter the password you want to use and click update on your post.

The next time you visit this page you will see a form where you need to enter the password for the page. If you have password protected pages then you need a way of giving the password to visitors. The default password protected text doesn't explain how you can get the password for the page. If you are giving out the password to certain visitors then this is fine, but if you want people to contact you asking for the password then you need to change the text that appears on the page. To change the text of the password protect content you need to use the filter of the_password_form, this will output all the html for the password form. As this returns all the form we need to use a string replace to find the text and replace it with anything you want. In the following example code you can change the password text to let the visitor know that they will need to email the site admin to request access to the password for the page and return the output of the form.

function change_password_protected_text($output)
    $adminEmail = get_option( 'admin_email' );
    $newPasswordText = 'This is a password protected page to request the password please email <a href="mailto:'.antispambot( $adminEmail ).'">'.antispambot( $adminEmail ).'</a>';
    $output = str_replace('This content is password protected. To view it please enter your password below:', $newPasswordText, $output);

    return $output;
add_filter( 'the_password_form', 'change_password_protected_text', 999);


Reliable uptime monitoring and instant alerts for any website downtime.

  • Uptime Monitoring
  • Performance Monitoring
  • SSL Certificate Alerts
  • Domain Monitoring
  • DNS Checker
  • XML Sitemap Monitoring