X

Add Post Formats Support

Snippets by IsItWP

Do you want to check if your WordPress theme supports post formats? Defining a format for your posts helps you to display them differently. We have created a quick code snippet that you can use to add post formats support in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

add_theme_support( 'post-formats', 
    array( 
        'aside', 
        'gallery',
        'link',
        'image',
        'quote',
        'status',
        'video',
        'audio',
        'chat'
    ) 
);
add_post_type_support( 'post', 'post-formats' );
add_post_type_support( 'page', 'post-formats' );

To check whether a post has a format or not, you can use this conditional tag in a template file:

if ( has_post_format( 'status' )):
  echo 'this is the status format';
endif;

You can also add the Format functionality to pages, or your own custom post type:

add_post_type_support( 'page', 'post-formats' ); // add to pages
add_post_type_support( 'books', 'post-formats' ); // add to custom post type books
add_theme_support( 'post-formats', array( 'status', 'gallery' ) );

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 25 best WooCommerce plugins to grow your sales and how to make an appointment booking system with WordPress.

Comments   Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!