WordPress: How to remove “Protected:” and “Private:” from post titles

May 23, 2012

By default, when creating a private or password protected post in WordPress the string “Private:” or “Protected:” is prepended to the post title on display (Never in the database, only when displaying). This can sometimes be annoying, however WordPress’ filters quickly come to the rescue here. There are two filters that add the text and I will show you how to remove the automatically added text below.

Remove “Protected:”

The WordPress filter for the protected pages is ‘protected_title_format’. It operates as you would normally expect a filter to. The WordPress core passes in a string that contains the title as ‘%s’.

The following code can be used to simply return the title without the Protected: in it

add_filter( 'protected_title_format', 'bl_remove_protected_title' );

function bl_remove_protected_title( $title ) {
    // Return only the title portion as defined by %s, not the additional 
    // 'Protected: ' as added in core
    return "%s";
}

Remove “Private:”

The WordPress filter for the private pages is ‘private_title_format’. It as with the filter above, it passes the title as ‘%s’.

The following code can be used to simply return the title with the Private: in it

add_filter( 'private_title_format', 'bl_remove_private_title' );

function bl_remove_private_title( $title ) {
    // Return only the title portion as defined by %s, not the additional 
    // 'Private: ' as added in core
    return "%s";
}

 

Resources

http://codex.wordpress.org/Function_Reference/add_filter
http://codex.wordpress.org/Plugin_API/Filter_Reference/protected_title_format
http://codex.wordpress.org/Plugin_API/Filter_Reference/private_title_format

5 thoughts on “WordPress: How to remove “Protected:” and “Private:” from post titles

  1. Nick (January 5, 2013)

    This function, for some reason, make the page unprotected. When clicking on the link (for me anyway) takes you straight to the page without asking for a password.

  2. Nick (January 5, 2013)

    Cancel that. The browser remembered the password.

    Thank you for the code!

  3. Aubrey Portwood (November 4, 2013)
    1. Ben Lobaugh (blobaugh) (November 4, 2013)

      Very cool! I see you posted about it too! http://aubreypwd.com/2013/remove-protected-wordpress-posts-titles-via-wordpress-plugin/

      Congrats on the plugin!

    2. chazdesimone (April 22, 2014)

      THANK YOU for the plugin. I have no idea where to add/modify code like it says above, so using a plugin is a must for me. Really appreciate this, Aubrey. You might like my latest piece of art about getting tech stuff “Up & Running”: http://amperart.com/index.php/2014/04/09/58-up-running/