I had the situation come up where I need a password-protected post in WordPress. Of course that is super easy in WordPress, you can set up a password for it right in the “Publish” box before publishing. But by default, WordPress appends “Protected: ” to the front of the post title, before and after the password has been entered. I didn’t like that, and thought that the password box was clue enough that the material was password protected.
I ran across some simple code in the official WordPress forums with a solution (thanks, t31os_!).
function the_title_trim($title) {
$title = esc_attr($title);
$findthese = array(
'#Protected:#',
'#Private:#'
);
$replacewith = array(
'', // What to replace "Protected:" with
'' // What to replace "Private:" with
);
$title = preg_replace($findthese, $replacewith, $title);
return $title;
}
add_filter('the_title', 'the_title_trim');
I saw a plugin to do this too, but I think since this is rather theme-specific, functions.php code makes the most sense.
![[ Digging into WordPress ]](http://digwp.com/wp-content/themes/DiggingIntoWordPress-2/images/sidebarbook.png)



An improvement would be to search for
__("Protected")so it’s even language independent :)If using this for a a generic theme, absolutely, best way to go.
This is filterable since WP v2.8, so it’s even easier:
add_filter('protected_title_format', 'blah');function blah($title) {return '%s';}Is that what you were after or did I miss something?
I’m really absent-minded sometimes. :-D Forgot to add that the same filtering works with
private_title_formattoo.Sweet. I’ll give that a shot, much cleaner.
Is this code work for on pages?
Why, instead of <?php the_title(); ?>, don’t you use <?php echo $post->post_title; ?>? It worked for me :).