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

Comments

  1. User Avatar
    Konstantin
    Permalink to comment#

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

    • User Avatar
      Ramses
      Permalink to comment#

      in wordpress 4.0 the first php code did not work, instead the second one worked! thanks man…

    • User Avatar
      Sue
      Permalink to comment#

      Perfect – exactly what I was looking for

    • User Avatar
      Ray
      Permalink to comment#

      Although I don’t understand php this works perfectly, exactly what I was looking for. Thanks

  2. User Avatar
    Anything Graphic
    Permalink to comment#

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

  3. User Avatar
    Imfromio
    Permalink to comment#

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

  4. User Avatar
    Moshe
    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'));

  5. User Avatar
    Gina

    Works great thanks!
    [Wordpress 3.3.2]

  6. User Avatar
    Steve
    Permalink to comment#

    You can also use the WordPress Helpers plugin.

    • User Avatar
      Errol
      Permalink to comment#

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

    • User Avatar
      Chantilly
      Permalink to comment#

      I installed the set of plugins for the Helper and was really glad to have done so. It solved a few problems, not all of them but- some of them. You have to first install Piklist, then follow that with Helpers. Piklist is in the plugins menu and the Helpers is under Available Tools. You only have to use Helpers to accomplish the edits and such that are available. Easy, and a video to help explain it (sell it- though it is free).

  7. User Avatar
    NONAME

    This didn’t work with Buddypress on my page.

  8. User Avatar
    http://legitphen375review.tumblr.com

    hey there and thank you for your info – I have
    certainly picked up anything new from right here.
    I did however expertise some technical issues using this website, as I experienced to reload the website lots of times previous
    to I could get it to load correctly. I had been wondering if your web hosting is OK?
    Not that I am complaining, but slow loading instances times will
    very frequently affect your placement in google and could damage your quality
    score if ads and marketing with Adwords. Well I am adding this RSS to my e-mail and can look out for a lot more of your respective exciting content.
    Make sure you update this again soon.

    Feel free to surf to my web blog; hunger suppressant foods [http://legitphen375review.tumblr.com](http:
    //legitphen375review.tumblr.com/ “http://legitphen375review.tumblr.com”)

  9. User Avatar
    Aubrey
    Permalink to comment#

    I just wrote a plugin for this too at http://wordpress.org/plugins/remove-protected/

  10. User Avatar
    ItKnol
    Permalink to comment#

    @Konstantin,
    using a filter is always the best solution.
    Any seasoned developer would disagree on using a regular expression on such a simple thing.

  11. User Avatar
    Fayssal
    Permalink to comment#

    Thanks a lot from Morocco

  12. User Avatar
    Ryan
    Permalink to comment#

    If you receive this error “attribute_escape is deprecated since version 2.8! Use esc_attr() instead”, just literally change “attribute_escape” to “esc_attr()”.

  13. User Avatar
    Erin
    Permalink to comment#

    Just tried this in WP 4.4.2 and it worked perfectly. Thank you!

  14. User Avatar
    Dawesi
    Permalink to comment#

    From wordpress Codex:

    https://codex.wordpress.org/Plugin_API/Filter_Reference/private_title_format

    /* Removing private prefix from post titles */

    function spi_remove_private_protected_from_titles( $format ) {
    return '%s';
    }
    add_filter( 'private_title_format', 'spi_remove_private_protected_from_titles' );

  15. User Avatar
    Sandy
    Permalink to comment#

    Thanks :)

  16. User Avatar
    BeardLantern
    Permalink to comment#

    Works like a charm. Absolutely beautiful. My Thanks! ^^

Submit a Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag