Intro to Post Formats in WordPress 3.1


WordPress 3.1 will introduce a simple new feature called “Post Formats” that should make theme developers very, very happy people. Although the feature is simple, in the hands of a creative designer it allows for some pretty major styling options with a single line of code.  If a designer also happens to have some minimal PHP savvy, it has some pretty tremendous creative potential.

Basically, Post Formats are just meta information and some front-end style additions to allow a theme author to customize individual posts both in “the Loop” and on single post pages.  Yes, it’s something that some theme authors have already been doing using categories or tags and some custom code — but this is easier and it also allows for some standardization and portability between themes which I think is the most important part.

At the time of this writing Post Formats is still in its early incarnation, so some things may change before the release of version 3.1.  That said, I think the feature is at a stage where we can start playing with it without much risk of major changes.

The basics:  Activating Post Formats

add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );

Post Formats in Publish Meta Box

That’s it!  That single line of code is all that’s needed to activate Post Formats in your theme.

Once active, a few things will automatically happen.

On the back-end, users will now be presented with a Format option in the Publish meta box of the post editor screen.

On the front-end, a couple of things happen. The post_class() function that most themes use to will start adding ‘format-‘ classes to each post wrapper and the body_class() function will add ‘single-format-‘ to the page body class.

A quick example of how to make use of this new class would could be as simple as this:

#content .format-default h2 {
   font-size: 32px;
   font-color: #333333;
}
#content .format-aside h2 {
   display: none;
}

In this example, we’re not doing much more than changing the title formatting of two post formats, but as you can imagine, this could be applied to every element of each post.

Supported Arguments

Post formats has just one argument.  The supported post formats.  Because this feature is intended to be standardized and portable between themes, custom formats are not an option. Currently supported (per the codex):

  • aside – Typically styled without a title. Similar to a Facebook status update.
  • chat – A chat transcript.
  • gallery – A gallery of images.
  • link – A link to another site.
  • image – A single image.
  • quote – A quotation.
  • status – A short status update, usually limited to 140 characters. Similar to a Twitter status update.
  • video – A single video.

Enable support for each post format by adding it to the array in add_theme_support.

Additional Functions:

At the moment, the post formats feature only brings one new function to the table:

get_post_format( $post->ID )

This returns the post format of the current post – very useful in a custom loop to take your customization’s further than you could with a pure CSS solution.

More Info

There’s already been a fair bit of discussion about why custom post formats aren’t being supported.  Frankly, the logic behind this is simple and solid:  the feature is designed to be portable and standardized.  Allowing for a custom option steps all over that logic — the instant ‘custom’ becomes an option, standards and portability go out the window.  As much as I’d like to see every feature in WordPress as customizable as possible, this is one case where I think it’ll be more globally beneficial to keep options broad but standardized.

If you can think of post formats that are missing, get yourself over to this trac ticket (#14746) and make your case for inclusion.

UPDATE:  Or join in here: http://wpdevel.wordpress.com/2010/11/11/list-of-post-formats/

13 thoughts on “Intro to Post Formats in WordPress 3.1

  1. It seems that post formats would help to overcome a lot of the “compatibility” issues associated with custom post types such as advanced pagination since the post is still registered as a “post”.

    Will post types work with all post types or just posts?

  2. @Gil: don’t forget about has_post_format() conditional as a new function, as well.

    @Ethan: it’s only for Posts. I was thinking about that earlier today; it’s not really needed for other post-types (Page, Custom Post Types), as those already can have custom Theme template files (page-custom-post-type.php, etc.).

  3. Pingback: WordPress 3.1 Post Formats Reference | Lisa Sabin-Wilson

  4. Pingback: WordPress 3.1 Post Formats Reference by Lisa Sabin-Wilson - WordPress, Multisite and BuddyPress plugins, themes, news and help – WPMU.org

  5. Pingback: » My First Post Format

  6. Pingback: What’s new and exciting in WordPress 3.1 | WPCandy

  7. Pingback: wpmag.com - WordPress News, Themes, Tutorials, Plugins, Questions, ...

  8. Pingback: Kanabův exprerimentální weblog » Post formats

  9. Pingback: WPSmith | Custom Post Types, Post Formats, Custom Taxonomies, and Custom Fields and Meta Boxes

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>