Using WordPress Post Formats

written by William Patton on July 29, 2012 in WordPress Custom with 3 comments

Uses of WordPress Post Formats

The list of what you can do with Post Formats is really only limited by the type of content (the actual formats defined by WordPress it’s self) and your imagination. I’ve personally used them myself to:

  • Give galleries custom CSS when on the Home page so that the whole gallery doesn’t show, just the excerpt and the Thumbnail of the gallery I have selected as the cover photo.
  • To add Facebook style style status updates on private pages to collaborate with other authors on blogs directly through the blog
  • Many More.

Most commonly I see them used like this:

  • Anything from custom layouts and displays.
  • Including (or excluding) other posts from specific pages.
  • Having specific pages dedicated to Videos or Links or any of the other formats.
  • Having special custom post format single pages – for instance you could have an image format post use 100% of the available width on the page, removing the sidebar completely.

There are near limitless ways to utilize the post formats so I won’t keep going with the list.

List of WordPress Post Formats

WordPress has built-in standardized Post Formats. These are listed below and can not be modified or added to by themes or even plugins. This is to ensure they are kept standardized to allow alliterative/offline blogging software the ability to utilize post formats when posting to WordPress from those external editors.

  • aside – Typically styled without a title. Similar to a Facebook note update.
  • gallery – A gallery of images. Post will likely contain a gallery shortcode and will have image attachments.
  • link – A link to another site. Themes may wish to use the first <a href=””> tag in the post content as the external link for that post. An alternative approach could be if the post consists only of a URL, then that will be the URL and the title (post_title) will be the name attached to the anchor for it.
  • image – A single image. The first <img /> tag in the post could be considered the image. Alternatively, if the post consists only of a URL, that will be the image URL and the title of the post (post_title) will be the title attribute for the image.
  • quote – A quotation. Probably will contain a blockquote holding the quote content. Alternatively, the quote may be just the content, with the source/author being the title.
  • status – A short status update, similar to a Twitter status update.
  • video – A single video. The first <video /> tag or object/embed in the post content could be considered the video. Alternatively, if the post consists only of a URL, that will be the video URL. May also contain the video as an attachment to the post, if video support is enabled on the blog (like via a plugin).
  • audio – An audio file. Could be used for Podcasting.
  • chat – A chat transcript, like so:

Enabling Post Formats on your WordPress Site.

Once you enable the Post Formats you then have the ability to select the post format via a radio button on the post editor page.

Parent Theme’s functions.php

Post Format support can be added to your theme in your themes functions.php file with one line of code.

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

That code adds an ‘aside’, ‘gallery’ and ‘link’ Post Format to your theme but you can add any of the formats listed above. Once enabled these are available to choose via a radio button when in the post editor.

Child Theme’s functions.php

You can add Post Formats via child themes too (and I highly recommend you do so rather than editing your chosen theme directly) but the process is slightly different. Any Post Formats added using add_theme_support OVERWRITES any previous call to it.  So if the parent theme adds support for ‘aside’, ‘status’ and ‘video’ post formats and then in the child theme you declare ‘video’, ‘status’, ‘gallery’ and ‘link’ you gain ‘gallery’ and ‘link’ but loose ‘aside’.

You also need to think about what order the function is called. It’s possible that the child theme will call it’s add_theme_support before the parent theme. The Post Formats you have added support for in your child theme would be overwritten by the parent theme’s. To avoid that you want to ensure that the call in your child theme is executed after any calls that come from the parent theme (or any call that may be added in a future update).

To add support to the child theme you need to create a function and hook into WordPress at a point after the call in the parent theme has occurred. Create your function and name it something simple but informative. Then hook into WordPress using the after_setup_theme hook. This almost guarantees that your code will run after the parent themes but just in case there is one little trick that’s always worth throwing in there: the $priority parameter. The add_action function below has 3 parameters: $tag, $function_to_add, $priority; $tag is where you want to ‘hook’ into, $function_to_add is the name of the function to be executed at that hook and $priority to tell WordPress what order to run the code in if there are multiple things to be done at that particular hook. $priority is an optional parameter and defaults to ’10’. Here we set ours to ’11’ to make sure that it’s executed after the parent theme’s code.

function child_postformats(){
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link' ) );

add_action( 'after_setup_theme', 'childtheme_formats', 11 );

Using Post Formats in your Theme

/* Post Type Selector */
if ( 'link' == get_post_format() ) {
/* Custom code for 'link' post format. */
} elseif ( 'aside' == get_post_format() ) {
/* Custom code for the 'aside' post format. */
} else {
/* Default code goes here. */

The codex page at suggests a different method of using the post formats as selectors: has_post_format

if ( has_post_format( 'video' )) {
echo 'this is the video format';

As you can see it’s as easy as using if else statement in your theme and telling it what code to execute upon that condition. My suggestion would be to use this selector on your front page and upon the post hitting the condition (be it image or video or whatever) calling a corresponding template file containing the loop for just that specific post format.

Have you used Post Formats before? Managed to create anything unique with them? Do you have an idea you want to talk through with someone? Then leave a comment below and I’ll get back to you ASAP.

Enhanced by Zemanta

Notice: WP_Query was called with an argument that is deprecated since version 3.1.0! caller_get_posts is deprecated. Use ignore_sticky_posts instead. in /var/www/html/wp-includes/functions.php on line 4080