X

How To Remove the Private or Protected Prefix From the Post Title

Snippets by IsItWP

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.

[code][/code]

Comments   Leave a Reply

  1. Very helpful! I used it with Code Snippets plug-in and it worked perfectly.

  2. I don’t see a snippet of code.

    1. Hey Kate,
      I just updated the post with the snippet.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!