Remove “Private:” From WordPress Titles

41

Posted by: Jennifer Zelazny on January 14, 2008

Categorized: WordPress, WordPress Logic

Tagged: , ,

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

function remove_private_prefix($title) {
$title = str_replace(
'Private:',
'',
$title);
return $title;
}
add_filter('the_title','remove_private_prefix');

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

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

  1. This is great. Thank you.

  2. Cecil says:

    Thanks for the tip! Very useful!

  3. oliver says:

    Thaanks. love you.

  4. Ohad Kless says:

    Hi,
    can you explain what to do so I can do the same for the category name in the sidebar?
    In other words – what should I put instead of $title and the_title to filter the category name for example in a category named Category_1, remove the _1 when showing in side bar?

    Thanks!

  5. jzelazny says:

    What are you using (which function) to list the categories?

  6. Gaz says:

    This is just what i needed and worked a treat. This has completed my wordpress makeover. I have managed to get my wordpress to make different post pages so i can have a blog within a blog. It was a piece of piss to rewrite wordpress to do it :) I needed some code like above to basically remove the words private from a certain page to which this has done. you can check my blog at http://www.astralprojectionuk.com. Many thanks!!!

  7. This worked like a charm, and the very first time. That NEVER happens! So I think you’re a genius and much appreciate the tip. I’ve passed it along in my blog.

  8. jzelazny says:

    Thanks – I am glad I could help!

  9. Worked perfectly thanks!!

  10. stawn says:

    You rule dude. Perfect.

  11. Lee says:

    Unreal! Thank you for this tip!

  12. loyapefef says:

    Interesting and informative, but would make something more on this topic?

  13. Sebastiaan says:

    Hi i can’t get it done using your suggestion.
    Tried to add the code to functions.php but no luck unfortunatly.

    Any tips? I am using K2 R7 theme.

    Thanks in advance!

  14. jzelazny says:

    Sebastiaan – if you want to send my your functions.php file I can take a look for you.

  15. Damien says:

    Thanks A lot !! that’s what Iwas lookink for. Great !

  16. Damien says:

    Thanks A lot !! that’s what I was looking for. Great !

  17. Blake says:

    Awesome thanks. Been looking for a way to do so.

  18. Andrew says:

    Thanks :)
    ~ Life life fully

  19. jcd3 says:

    seriously, that rocks! =)

  20. 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.

  21. 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… ;)

  22. ronal says:

    you the man

  23. 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 :-)

  24. Michael says:

    Works perfectly. Thanks for sharing.

  25. 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.

  26. Jessie says:

    Wow! Thanks so much for that! Worked perfect!

  27. Dr Jon says:

    Top man :)

  28. Jake says:

    You’re the tops! Thanks!

  29. Victor says:

    Thanks mate, top work! :)

  30. Rafael says:

    Sorry guys, I’m not that smart in terms of programmimg, jejeje, where do I have to paste this code?

  31. Ben says:

    Niiiice. Blink! And its gone. Keep it up!

  32. PaTwRiK says:

    Tried it but didn’t work…Found “Exclude Page” Plugin…works like a charm

  33. That was awesome! So helpful.

  34. Kimberly says:

    excellent line of code! I’ve been trying to figure out all day how to make some pages still viewable but not on my navigation. Thanks again for posting this!

  35. Jason Grim says:

    A better filter to use would be “private_title_format” rather than “the_title”

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>