Removing Protected and Private from WordPress posts

By default WP will prepend Protected to any post title that is protected by a password and will prepend Private to any that is set as private, let's fix that

By default WordPress will prepend the copy "Protected: " to any post title that is protected by a password and will prepend the copy "Private: " to any post title that is set as a private post.

I can see the sense in doing this, in a lot of cases you want to clearly mark those posts as such. In my use case though I am helping theme a site for a photographer, and all his client photos are password protected, in this case having the extra "Protected" copy just looks ugly.

Happily there is a really simple fix you can apply to kill this wording, add the following snippet to your theme's functions.php file.


function protect_my_privates($text){
  $text='%s';
  return $text;
}
add_filter('private_title_format','protect_my_privates');
add_filter('protected_title_format', 'protect_my_privates');

What this does is tells both private_title_format and protected_title_format that we just want to pass through the title and not append or prepend anything to it.

If you did want to do something special to the text you could always edit $text to be something like;


$text = '[protected]%s[/protected]'

This will make a title that is called "Hello World" appear like "[protected]Hello World[/protected]"


Recent posts View all

Ruby

What are the square brackets in my Rails migrations?

Let's look at what these little square brackets are doing in our Rails migration files

Web Dev

Setting a minimum TLS version with CloudFlare

How to set a minimum TLS version on CloudFlare and why you should consider it