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)
This is great. Thank you.
Thanks for the tip! Very useful!
Thaanks. love you.
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!
What are you using (which function) to list the categories?
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!!!
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.
Thanks – I am glad I could help!
Worked perfectly thanks!!
Glad it helped!
thank you!
No problem!
You rule dude. Perfect.
Unreal! Thank you for this tip!
Interesting and informative, but would make something more on this topic?
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!
Sebastiaan – if you want to send my your functions.php file I can take a look for you.
Thanks A lot !! that’s what Iwas lookink for. Great !
Thanks A lot !! that’s what I was looking for. Great !
Awesome thanks. Been looking for a way to do so.
Thanks 🙂
~ Life life fully
seriously, that rocks! =)
Glad it helped out!
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.
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… 😉
you the man
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 🙂
Works perfectly. Thanks for sharing.
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.
Wow! Thanks so much for that! Worked perfect!
Simple and works. Thanks
Top man 🙂
You’re the tops! Thanks!
Thanks mate, top work! 🙂
Sorry guys, I’m not that smart in terms of programmimg, jejeje, where do I have to paste this code?
PERFECT.
Niiiice. Blink! And its gone. Keep it up!
Tried it but didn’t work…Found “Exclude Page” Plugin…works like a charm
That was awesome! So helpful.
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!
A better filter to use would be “private_title_format” rather than “the_title”
THANK YOU!!!