Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
Please take care of the license of that icon : icons.iconarchive.com/icons/dryicons/aesthetica-2/readme.txt - I added your description accordingly. –  hakre Nov 16 '10 at 2:47

1 Answer 1

up vote 4 down vote accepted

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="http://i.stack.imgur.com/aIDa6.png" title="'.htmlspecialchars($text).'"/>';

    return $post_states;
}
share|improve this answer
    
@hakre: htmlspecialchars() or the more WordPress-ey esc_attr()? (I hope the @-reply notifies editors of posts too) –  Jan Fabry Nov 16 '10 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> –  NetConstructor.com Nov 16 '10 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 '10 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 '10 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 '10 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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