Search
Close this search box.

A Guide to WordPress Post Formats

Post formats are one of the most interesting additions to WordPress 3.1. In this post we learn how to use them.
Table of Contents

Sponsored Ad

If you purchase through a link on our site, we may earn a commission.

Post formats are one of the most interesting additions to WordPress 3.1.

They enable us to apply different styling to a particular post type (e.g. page or post) by choosing from one of the types provided by WordPress itself:

  • aside –Β  A short piece of content, typically styled without a title.
  • gallery – A gallery of images.
  • link – A single link to another site.
  • image – A single image.
  • quote – A single quotation.
  • status – A short status update, similar to a Twitter status update.
  • video – A single video.
  • audio – A single audio file.
  • chat – A chat transcript.

How to add Post Format Support

Adding theme support for post formats is very easy, just paste the following into your functions.php file.

[php]add_theme_support(‘post-formats’, array( ‘aside’, ‘chat’, ‘gallery’, ‘image’, ‘link’, ‘quote’, ‘status’, ‘video’, ‘audio’));[/php]

Of course, if you don’t require the full set of post formats, just omit the ones you don’t need from the array.

Now check out your post editor and you will see a new ‘Format’ box in the right hand side bar.

Displaying different Post Formats on your site

In order for your post formats to show up with their own structure and styling on the site, you need to modify your theme. Ideally you use something similar to this code:

[php]
if (have_posts()) :
while (have_posts()) : the_post();
if(!get_post_format()) {
get_template_part(‘format’, ‘standard’);
} else {
get_template_part(‘format’, get_post_format());
}
endwhile;
endif;
[/php]

WordPress will thus check if there are any post formats present, then load the appropriate template according to the format it finds.

Improvements

When Post Formats came out many people were asking why WordPress doesn’t have a customised UI for each Post Format (as is the case with the Tumblr service). This might well be the case in the future, but for now, the format is the same whatever Post Format you choose (Title and Post Editor). If you need a custom UI (especially if you are designing this for a client), the solution can be that of using Custom Meta Boxes. If you need to display different meta boxes for different post formats, a partial solution using JQuery can be found here.

At the moment it is not possible to add any custom post formats, although there is the possibility that the feature might be included in future releases.

If you enjoyed this post, make sure to subscribe to WPMayor’s RSS feed.

Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Sponsored Ad

If you purchase through a link on our site, we may earn a commission.

All suggestions are anonymous.

More from our blog...

Post a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Stay updated with WP Mayor's newsletter showcase every week

Stay on top of every new WordPress innovation and latest launches. Receive all our fresh product reviews and expert guides directly in your inbox.

Hosting Survey 2024

Are you happy with your hosting provider or are you over-paying for too little? Have your say below!

"*" indicates required fields

What's the main reason you picked this host?*
How happy are you with your host?*

OPTIONAL: If you'd like to receive the results of this survey, please enter your details below.