How To Add Post Formats To WordPress Theme Using Theme Support?

Do you know what are post formats and how to add post formats to WordPress Theme? Post formats are the special types of posts other than the standard post.

When you publish any blog post then it seems like a simple post on your blog. What would you do to create a gallery using the WordPress?

How would you show a link to any website with a better design? All these tasks can be completed using the WordPress post formats.

In this tutorial, you will learn how to add post formats to your WordPress theme and the types.

Before You Add Post Formats In WordPress Theme, You Should Know About All of The Types.

Just like the custom header, navigation menu, featured image, you can add the theme support option for post formats.

Post formats are the special types of posts which would let you show the posts in a different way. The format of the post would be different from the normal post.

There are many post formats.

1. aside:- It is a kind of post format which basically doesn’t contain the title of the post. It’s like a sticky post which can be designed to show it on the top.

Suppose you want to take a break then you can use this post format to let your readers know. Most of the people use it to show a paragraph or any update.

2. gallery:- After adding this post format, you would be able to create a gallery from your WordPress post editor. It would be published just like your ordinary posts but the images will be shown.

You can choose many images along with the title of the post. Though the design would vary from theme to theme but still, the basic idea is to show a group of images.

3. link:- If you want to link the content to any other website then you can use the Link post format. Just like all other posts, the Link post would appear and the content would be heading to any other content.

4. image:- There would be a single post showing like a post. Most of the time, an image would be the first image of the post. The image URL would be the post URL.

5. quote:- If you want to show any statement in a quote then this post format will let you do that.

6. status:- Just a simple and short status update about your website. It doesn’t contain more characters.

7. video:- As its name suggests, you can enable post format to add the single video or the playlist.

8. audio:- Though there is an another way to embed audio in the blog post but still if you want an audio itself as a post then use this post format.

9. chat:- You can add the simple chat transcript.

You Can Add Post Formats To WordPress Theme Using The Theme Support Option.

To jump into this, you must have the basic knowledge of PHP and HTML. If you’re a developer then you would be amazed to know that WordPress has many things to do with.

Let me show you the code to add the theme support for post formats.

In the functions.php file of your theme, add the code.

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

In the above code, there are three post formats. You can add as many you want.

After this line of code, you would notice a nice box in your WordPress post editor showing all the types of post formats.

While you publish any post, you can select its format.

How Would You Show The Post Formats on Your Website?

If you have a little bit of knowledge about theme development then it won’t be so hard. There are some loops and conditional statements which can be used to show post formats.

The WordPress function you should use.

has_post_format();

You can handle the output of every post format. Let me show you an example.

if ( has_post_format( ‘video’ ) ) {

echo ‘this is a video’;

}

else if ( has_post_format( ‘aside’ ) ) {

echo ‘this is aside post format’;

}

else{

echo ‘no post’;

}

In the above code, two post formats have been added. If one is available then it will be published otherwise, next with their respective output.

And if you want to use one file at many places then you can use the get_template_part(); function along with the post formats in it.

When you add post formats in WordPress theme, the main code is the theme support code. It’s like adding a button to support, but the working is yet to be configured.

Can You Now Add Post Formats To WordPress Theme And Handle The Output Using Loops?

Though you can add post formats to WordPress theme but still, you have to handle the output using the conditional statements.

In most of the WordPress themes, you would notice the above-mentioned post formats. The basic post formats you can use are aside, gallery, and link.

Just use the theme support function and enable post formats in WordPress.

by Ravi Chahar

A WordPress Professional and the LinkedIn Influencer. A coder by passion and a blogger by choice. WordPress theme development is his forte. He is your WordPress guy who will teach you how to solve WordPress errors, WordPress security issues, design issues and what not.

Get Free Updates Into Your Inbox

Learn Everything Just Like I Did

SUBSCRIBE

4 comments

  1. Hey Ravi,

    This is great! I didn’t realize all the different types of posts and what they all meant. I guess I never really focused on it. However, knowing now what you’ve shared with us and how to use the code to publish it, I think I might give it a try.

    Going to save the page for future reference. Thanks again!

    Bren

    1. Hi Bren,

      There are many post formats but we don’t really use them. To use these formats, you should have a theme which has enabled them. The code shown above can help you add the theme support for all the post formats.
      Thanks for stopping by.
      Have a great day.
      ~Ravi

  2. Hi Ravi,

    This sounds like a really cool way to diversity the look and feel of your blog.

    Instead of making everything uniform and symmetrical, you can use posts to throw in different things in different formats.

    I love this idea ?

    Thanks for showing us how to get this done.

    -Donna

    1. Hey Donna,

      Yeah, it’s kind of great idea to use different kinds of post formats. You can build a gallery to publish as a post. All the different features of WordPress are cool.
      Thanks for commenting.
      ~Ravi

Leave a Reply

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