Quick Tip: Changing the Password Protected Text in WordPress

When password protecting a post in WordPress, the default text is often not quite right. In this quick tip, you'll learn how to easily change the password protected message in WordPress.

Note that he following tutorial teaches you how to change the text as a plugin, however, the main code can be simply added to your theme's functions.php file instead.

Step 1

You should create a new folder in your WordPress site's plugins directory, and give it a title - I'll call it protected-text.

Step 2

Create a new file, called protected-text.php and add the following plugin information to the file:

This text simply tells WordPress about the plugin, and ensures that it displays in the Plugins page in the WordPress admin.

Step 3

The first section of code checks to see if the post is password protected, and if there's already a cookie stored from a previous successful login.

Step 4

If the post is password protected, and there isn't already a cookie, the password form is output. This plugin overwrites the whole password protected function, so we need to add the form as well as our new message.

You can add your main message in the space where I've written "Add your custom message!", and the label for the password field in the label for="post_password" section.

Step 5

There's also an else statement, so that if the post isn't password protected, or there's already a cookie, it knows what to do. In this case, it'll simply display the post content.

Step 6

The final step is to tell WordPress to use our new function when loading any content. This can be achieved with a simple add_filter command.

In Summary

That's it - you've now made a simple plugin to overwrite the standard password protected form! You can download the source code for this project above.

If you have any questions, please feel free to leave a comment below.

Tags:

Comments

Related Articles