treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Remove Private/Protected from Post Titles

Last updated on:

For the functions.php file in your theme:

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');
View Comments

Comments

  1. Or you do it like that:

    function title_format($content) {
    return '%s';
    }
    add_filter('private_title_format', 'title_format');
    add_filter('protected_title_format', 'title_format');

  2. Victor Meyer
    Permalink to comment#

    Thanks man!

  3. Thank you so much! This was bothering me on a client site I am developing.

  4. Permalink to comment#

    @konstantin
    That’ perfect. Very clean and simple and, most importantly, worked like a charm!

  5. Worked perfectly, thanks!

  6. Permalink to comment#

    WordPress 3.3: incorrect.

    There is no such function in functions.php.

    Instead, go to post-template.php and in the function called get_the_title() change this line:

    $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));

  7. Works great thanks!
    [Wordpress 3.3.2]

  8. Permalink to comment#

    You can also use the WordPress Helpers plugin.

    • Errol
      Permalink to comment#

      How do you use the WordPress Helpers plugin to accomplish this? Can you give more detail?

Leave a Comment

Use markdown or basic HTML and be nice.