Remove “Private:” From WordPress Titles

I needed to be able filter out the text "Private:" for posts and pages that were password protected but did not want to edit any core WordPress files. To filter out that text, I added the following code into my functions.php file (within my theme directory):

PHP:
  1. function remove_private_prefix($title) {
  2. $title = str_replace(
  3. 'Private:',
  4. '',
  5. $title);
  6. return $title;
  7. }
  8. add_filter('the_title','remove_private_prefix');

(I also posted this filter in the WordPress Support Forum)

31 Responses to “Remove “Private:” From WordPress Titles”

  1. Andrew says:

    Thanks :)
    ~ Life life fully

  2. jcd3 says:

    seriously, that rocks! =)

  3. Enrico says:

    I try your script, it works very well, but it replaces every instances on “the_title()” template function.
    I’ve replaced

    add_filter(‘the_title’,'remove_private_prefix’);

    with

    apply_filters(‘the_title’,'remove_private_prefix’);

    and then replaced only that I’d like to filter with

    (take a look to wp-codex for more documentation).

    I think it could be more flexible, will you?
    Thanks.
    Enrico.

  4. Enrico says:

    Sorry “php” snippets was removed from my comment… I mean

    …and then replaced only ” the_title()” I’d like to filter with ” remove_private_prefix(the_title(”,”,false))” …

    sorry… ;)

  5. ronal says:

    you the man

  6. Russ says:

    This worked well,. I had to remove defaulted numbers 1 -7 that somehow found their way into the copy & paste routine,.. and then just pasted it after the defaulted php call in the functions.php before the end ?> bracket and it worked like a charm.
    Thanks a lot :-)

  7. Michael says:

    Works perfectly. Thanks for sharing.

  8. jrwills says:

    Thanks! It is perfecto and now I don’t have to explain to folks that it isn’t really private, I just didn’t want it on my pages menu.

    Good stuff.

  9. Jessie says:

    Wow! Thanks so much for that! Worked perfect!

Leave a Reply