Remove ‘Private’ or ‘Protected’ from post titles

October 2, 2019
9:20 AM
0

AdvancedBeginnerPHPWordpressWP FilterWP PostWP Title

Remove ‘Private’ or ‘Protected’ from post titles

By default, WordPress adds a prefix “Private: ” or “Protected: ” to all posts marked as Private or Protected. For that to be removed we have a wordpress filter.

function remove_title_prefix ($title) {
    $title = attribute_escape($title);
    $find = array(
        '#Protected: #', // Notice the blank space after Protected:
        '#Private: #' // Notice again, otherwise the title get pushed.
    );
    $replace = array(
        '', // What to replace "Protected: " with
        '' // What to replace "Private: " with
    );
    $title = preg_replace($find, $replace, $title);
    return $title;
}
add_filter('the_title', 'remove_title_prefix');

Just add the above code snippet to your theme’s functions.php  file and the prefix from your post will be gone.


About Author

Karthikesavan

I'm the founder of Proficient Designers. I'm a full time PHP, Wordpress, Android app and UI/UX developer who is passionate in coding.

Comments & Replies