How To Add Post Formats To Your WordPress Theme

How To Use Custom Template For Post Formats In WordPress

Have you seen any premium or custom WordPress theme with different post styles and template for every post format? Most of you have already seen it, but in case you have not seen anything like that, you can head over to my personal blog – HardeepAsrani.com.

If you’re using post formats in your WordPress themes, then you might wanna use a custom template for posts formats to make them look more meaningful. In this tutorial, I’ll show you how to use custom template files for posts formats in your WordPress blog. I’ll show you two different ways to do that.

Add Post Formats Support To Your Theme

In order to use post formats in your WordPress posts, you need to add format support to your current theme (if it doesn’t exist). You can head over to this link for more info.

Using Post Loop (Level: Experienced)

If you just want to change the loop of your format posts, then this trick is for you. We will use a single.php file with multiple loops for various formats.

Add following code to your single.php‘s loop:

Now, create and upload your custom format loops files to the root of your current theme. Evert post format template file should be named content-{post-format}.php. Example: content-video.php and content-audio.php

Also, don’t forget to add a content.php file as well, because it will be the default file to fall back to as a default.

Using Custom Single.php File (Level: Newbie)

If you’re a newbie or don’t want to mess with your post loop, then this trick is for you. We will create a custom template file for Video format, and will be naming it single-video.php.

[alert style=”yellow”]Tip: You can also copy your single.php file to this template and make some changes that you want in the custom template.[/alert]

Add your single-video.php to your current theme’s root and drop the following snippet to functions.php file:

Now, all posts with video format will use single-video.php file as its template.

Update

You can also use the following snippet to add support for format specific template for all formats:

Now, just use single-{format name}.php format for the formats that you’re using.