Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Support different post formats on posts and custom post types in WordPress
add_theme_support( 'post-formats', array( 'gallery', 'link', 'quote', 'audio', 'video' ) );
add_post_type_support( 'cpt_portfolio', 'post-formats' );
function adjust_post_formats() {
if ( isset( $_GET['post'] ) ) {
$post = get_post( $_GET['post'] );
if ( $post ) {
$post_type = $post->post_type;
}
} elseif ( ! isset( $_GET['post_type'] ) ) {
$post_type = 'post';
} elseif ( in_array( $_GET['post_type'], get_post_types( array( 'show_ui' => true ) ) ) ) {
$post_type = $_GET['post_type'];
} else {
return;
}
if ( 'cpt_portfolio' == $post_type ) {
add_theme_support( 'post-formats', array( 'gallery', 'video', 'audio' ) );
} elseif ( 'post' == $post_type ) {
add_theme_support( 'post-formats', array( 'gallery', 'link', 'quote', 'audio', 'video' ) );
}
}
add_action( 'load-post.php', 'adjust_post_formats' );
add_action( 'load-post-new.php', 'adjust_post_formats' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.