Really Simple Custom Post Formats

WordPress 3.1 will come with a standardized set of post formats just like Tumblr currently supports. You can read more about it on WPDevel. But what to do if you don’t want to wait for WordPress 3.1 or you think you need to add some more specific post formats?

Well luckily giving the impression of Post Formats is really simple. All you need is the right filter. In this case display_post_states. In my example I’m using tags to check for a post format but you can use category, metakey, custom taxonomy etc.

add_action('init','post_format_testing_init');
function post_format_testing_init(){
    add_filter('display_post_states',
               'custom_format_display_post_states');
}
global $custom_post_formats;
$custom_post_formats=array('image','article','audio','media');
function custom_format_display_post_states($poststates){
    global $custom_post_formats;
    global $post;
    $tags=get_the_tags($post->ID);
    if($tags)
        foreach($tags as $tag)
            if(in_array($tag->slug,$custom_post_formats)){
                $poststates[]="[$tag->slug]";
                break;
            }
    return $poststates;
}

The above code yields the following result:

Go ahead and add this to your themes for a better user experience. I know at least one premium theme provider could use it.

PS
With a little jQuery (input[@name=post_format]:change + some other stuff) and a hidden custom field you can most likely extend the upcoming default post formats with your own and have it nicely integrated with the default Post Format list. So no need for the user to add tags, categories etc to select a Post Format. But more on that in another post.

Don't be a lurker, voice your oppinion.

Leave a Reply

Keywords are not a name. If you use keywords for a name you get marked as spam, this goes for writing them in french, german etc.

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Get Adobe Flash player