Are you looking for a way to remove the private or protected prefix from post title? This snippet removes the description prepended to the post title when a post’s visibility is either Password protected or Private.
Instructions:
Add this code to your theme’s functions.php file or in a site-specific plugin. Note: If the language on your site is not English, you should replace Protected
and Private
text in the code below with the corresponding words in the language you are using on your site.
<?php function the_title_trim($title) { $title = attribute_escape($title); $findthese = array( '#Protected: #', // Notice the blank space after Protected: '#Private: #' // Notice again, otherwise the title get pushed. ); $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'); ?>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: CSS Hero Review: #1 WordPress Theme Customization Plugin.
Very helpful! I used it with Code Snippets plug-in and it worked perfectly.
I don’t see a snippet of code.
Hey Kate,
I just updated the post with the snippet.