WordPress

Post Formats

Remarks#

The following Post Formats are available for users to choose from, if the theme enables support for them.

Note that while the actual post content entry won’t change, the theme can use this user choice to display the post differently based on the format chosen. For example, a theme could leave off the display of the title for a “Status” post. How things are displayed is entirely up to the theme, but here are some general guidelines.

audio - An audio file or playlist. Could be used for Podcasting.

  • chat - A chat transcript

Adding post type to Theme

Add post-formats to post_type ‘page’

add_post_type_support( 'page', 'post-formats' );

Next example registers custom post type ‘my_custom_post_type’, and add Post Formats.

Register custom post type ‘my_custom_post_type’

add_action( 'init', 'create_my_post_type' );
function create_my_post_type() {
    register_post_type( 'my_custom_post_type',
      array(
        'labels' => array( 'name' => __( 'Products' ) ),
        'public' => true
    )
  );
}

Add post-formats to post_type ‘my_custom_post_type’

add_post_type_support( 'my_custom_post_type', 'post-formats' );

Or in the function register_post_type(), add ‘post-formats’, in ‘supports’ parameter array. Next example is equivalent to above one.

Register custom post type ‘my_custom_post_type’ with ‘supports’ parameter

add_action( 'init', 'create_my_post_type' );
function create_my_post_type() {
    register_post_type( 'my_custom_post_type',
      array(
        'labels' => array( 'name' => __( 'Products' ) ),
        'public' => true,
        'supports' => array('title', 'editor', 'post-formats')
    )
  );
} 

Add Theme Support for post

Function Call

add_theme_support( 'post-formats' )

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow