In Wordpress, whenever a post is password protected the backend admin area appends the text in bold "- Password protected" after the post title.

What I am looking for is a way to remove this text and instead have it utilize an icon (link below) which should be appended before the title text.

How can this be done?

I want to use an Icon from the Aesthetica Icon Set by http://dryicons.com: alt text


1 Answer 1


Try this (don't forget to replace icon URL):

add_filter( 'display_post_states', 'password_protected_icon' );

function password_protected_icon( $post_states ) {

    $text = __('Password protected');
    $pos = array_search( $text, $post_states);
    if( false !== $pos )
        $post_states[$pos] = '<img src="https://i.stack.imgur.com/aIDa6.png" title="'.htmlspecialchars($text).'"/>';

    return $post_states;
  • @hakre: htmlspecialchars() or the more WordPress-ey esc_attr()? (I hope the @-reply notifies editors of posts too)
    – Jan Fabry
    Nov 16, 2010 at 11:23
  • @Rarst -- thank you very much for your answer. Your solution almost works. It does replace the text "password protected" however I was looking for a way to place the icon "before" the post title text. Also, I would like to remove the "-" from the end of the post title. It seems it adds the following: - <span class='post-state'>Password protected</span> Nov 16, 2010 at 14:04
  • Unfortunately I don't see easy way to do that. There is no filter for concatenated post states output and it is called directly in template, not easy to override.
    – Rarst
    Nov 16, 2010 at 14:34
  • @jan - I shortly thought about an alternative as well, but I preferred htmlspecialchars() as it is a native PHP function, it does exactly what I was looking for and it won't get renamed or broken. So esc_attr look like overhead only to me. No Idea what that has been created as there was unsolved problem that it tries to solve. Just take a look into the esc_attr() and related code, then you see what I mean.
    – hakre
    Nov 16, 2010 at 16:23
  • 1
    @NetConstructor.com - you probably can add a class to the image, and then do some CSS magic to place the icon in front of the post title if more control via PHP is not possible like Rarst wrote.
    – hakre
    Nov 16, 2010 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.