First of all themes need to use add_theme_support()
in the functions.php
file to tell WordPress
which post formats to support by passing an array of formats like so:
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
Note that you must call this before the init hook gets called! A good hook to use is the after_setup_theme
hook.
Then by code you can add the post formats like below-
//add post-formats to post_type 'your_custom_post_type'
add_post_type_support( 'your_custom_post_type', 'post-formats' );
Also can add support on creation of post type like below-
// register custom post type 'your_custom_post_type' with 'supports' parameter
add_action( 'init', 'create_your_post_type' );
function create_my_post_type() {
register_post_type( 'your_custom_post_type',
array(
'labels' => array( 'name' => __( 'Products' ) ),
'public' => true,
'supports' => array('title', 'editor', 'post-formats')
)
);
}