Remove “Private:” From WordPress Titles

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

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)

43 thoughts on “Remove “Private:” From WordPress Titles”
  1. C. Tyson Edwards |

    This is great. Thank you.

  2. Cecil |

    Thanks for the tip! Very useful!

  3. oliver |

    Thaanks. love you.

  4. Ohad Kless |

    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 |

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

  6. Gaz |

    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. Susan Livingstone |

    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 |

    Thanks – I am glad I could help!

  9. Matt McGuire |

    Worked perfectly thanks!!

  10. nj |

    thank you!

  11. stawn |

    You rule dude. Perfect.

  12. Lee |

    Unreal! Thank you for this tip!

  13. loyapefef |

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

  14. Sebastiaan |

    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!

  15. jzelazny |

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

  16. Damien |

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

  17. Damien |

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

  18. Blake |

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

  19. Andrew |

    Thanks 🙂
    ~ Life life fully

  20. jcd3 |

    seriously, that rocks! =)

  21. Enrico |

    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.

  22. Enrico |

    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… 😉

  23. ronal |

    you the man

  24. Russ |

    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 🙂

  25. Michael |

    Works perfectly. Thanks for sharing.

  26. jrwills |

    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.

  27. Jessie |

    Wow! Thanks so much for that! Worked perfect!

  28. Dr Jon |

    Top man 🙂

  29. Jake |

    You’re the tops! Thanks!

  30. Victor |

    Thanks mate, top work! 🙂

  31. Rafael |

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

  32. Ben |

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

  33. PaTwRiK |

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

  34. Ian L. Gordon |

    That was awesome! So helpful.

  35. Kimberly |

    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!

  36. Jason Grim |

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

  37. Rixtertrader |

    THANK YOU!!!

Leave a Reply

Your email address will not be published.
*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.