10 · 29

Remove ‘Protected’ text from WordPress Password Pages | WebDesign & Such

Here is a great WordPress article from Web Design & Such!

WordPress has a built in password protection feature for pages or posts. I was recently developing a site for a client in WordPress, and decided to use this feature. The client wanted to have a page of their website with a Calendar of Events with a password on the page. The purpose was to keep non-members from seeing the Calendar. I decided this was simple enough, and since I was building the site in WordPress I figured I might as well keep it simple and use the built in password protect feature.

So I created the page and added the password from within the WordPress control panel:
(and NO, I don’t use the password ‘SecretPage!!’ on anything, so don’t bother):

Once that was all set I checked out the page:

My page title was “Calendar of Events”. The image above is a sceenshot of what I saw.
There are a few problems that I saw immediately. All of the text that WordPress uses for its password protect feature would need to be changed. First of all, I don’t need the text “Protected:” .. I mean, obviously it’s protected, it says that right below!! Speaking of which, all that text needed to be changed also (this post is password protected…). It really didn’t make sense, since it wasn’t a post, it was a page (using WordPress as a CMS, booya ;) ).

Most things in WordPress are easy and since this is live text I assumed it would be pretty easy to change once I tracked down the source, but I was wrong. After a little interwebs searching, I found out that the text is actually located in the wp-includes folder. The problem with changing anything in there is that the wp-includes folder gets updated with each WordPress install, so it might overwrite any changes I made. I don’t need a client coming back to me every time they update their WordPress version and their text “suddenly changed“.

After searching a few forums and trying a few different things I found a combination of code that achieved what I was trying to do. By putting the following code in your functions.php file you can choose what each line of text says. Or in my case, remove the ‘Protected‘ text from the WordPress password protected page, and edit the ‘This post is password protected. To view it please enter your password below” text. Here’s the code to put in your function.php file (in between the PHP tags):

function the_title_trim($title)
{
$pattern[0] = ‘/Protected:/’;
$pattern[1] = ‘/Private:/’;
$replacement[0] = ”; // Enter some text to put in place of Protected:
$replacement[1] = ”; // Enter some text to put in place of Private:

return preg_replace($pattern, $replacement, $title);
}
add_filter(‘the_title’, ‘the_title_trim’);
function change_pw_text($content) {
$content = str_replace(
‘This post is password protected. To view it please enter your password below:’,
‘This page is for WebDesignAndSuch.com Members. Please enter your password:’,
$content);
return $content;
}
add_filter(‘the_content’,'change_pw_text’);

And here’s my final result. Much cleaner looking, makes more sense, and is even more user friendly since it explains exactly to the user why they can / can’t see or have access to the page.
*One quick thing, the above code also works for the WordPress Private posts / pages function.