Image may be NSFW.
Clik here to view.If you make a post private in WordPress, the post’s title with be prefixed with “Private”. The same will happen if you password protect the post, although it will be prefixed with “Protected”. I don’t find it very appealing to have the word ‘Protected’ or ‘Private’ in the post titles. This can sometimes be annoying, however WordPress’ filters quickly come to the rescue here. Do you want to remove Private and Protected from WordPress posts and pages?
The only thing you have to do is to paste the following snippet in your theme’s functions.php file to remove words from post titles. Once you’ll save the file, the hack will be applied to your your posts.
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');
If you want to replace the words with something of your own, you can add them by customizing the snippet. By default, it is blank to delete the word altogether. If your language is not English, you can replace Protected & Private with the corresponding words in your language.
Credits goes to Chris Coyier for this awesome piece of code. Have you checked out the book Chris wrote with Jeff Starr? It’s called Digging into WordPress and it is a must-have for all WordPress fans!
If you enjoyed this article,please consider sharing it!!
The post How to Remove Private and Protected From Post Title in WordPress! appeared first on WordPress Experts.