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