A Web Design Community curated by Chris Coyier

Code Snippets Gallery

Code Snippets > WordPress > Remove Private/Protected from Post Titles Submit one!

Remove Private/Protected from Post Titles

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

3 Responses

  1. Konstantin says:

    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 says:

    Thanks man!

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

Leave a Comment

Remember:
  • Be nice.
  • Wrap multiline code in <pre> and <code> tags and escape it first (turn <'s into &lt;'s).
  • You may use regular HTML stuff like <a href="">, <em>, and <strong>
* This website may or may not contain any actual CSS or Tricks.