Customize the “protected post” text

Posted on

Password protected pages are such a great feature of WordPress (under-used, probably too) but one of the things I don’t like about them is the text it puts in the title that says “Protected:” or “Private:.”

Well if you ever want to get rid of that here is a little something to add to your functions.php file.

/**
*Remove protected from the title of the form
**/

function the_title_trim($title) {
	$title = attribute_escape($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');

And if you want to change the text that asks for the password, to something more explanatory (like for internal staff) use this:

/**
Change the text on the password screen 
**/

function change_pw_text($content) {
$content = str_replace(
   'This post is password protected. To view it please enter your password below:',
   'Hello staff members! To access these documents here please enter the password provided by [so and so]. If you have any technical problems contact [somebody] at the Office.',
   $content);

return $content;
}
add_filter('the_content','change_pw_text');
Posted in Wordpress Tips, Tricks and Reusable Bits of Code.