21

the thumbnail support is working for post, but I have another post type called product and it is not working for this. I am trying: add_theme_support( 'post-thumbnails', array( 'post', 'product' ) ); I am also using the multiple post thumbnail plugin.

3 Answers 3

34

By default all custom post adds support for Title and editor, if you want more stuff like comments, thumbnail and revisions you have to add it manually in the support argument.

Read more about how to register your custom post type here, you can also find the section about support to see what you can add.

Here is an example wehere to register thumbnail for the custom post "Books" and it hav support for: 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'

function codex_custom_init() {
  $labels = array(
    'name' => _x('Books', 'post type general name'),
    'singular_name' => _x('Book', 'post type singular name'),
    'add_new' => _x('Add New', 'book'),
    'add_new_item' => __('Add New Book'),
    'edit_item' => __('Edit Book'),
    'new_item' => __('New Book'),
    'all_items' => __('All Books'),
    'view_item' => __('View Book'),
    'search_items' => __('Search Books'),
    'not_found' =>  __('No books found'),
    'not_found_in_trash' => __('No books found in Trash'), 
    'parent_item_colon' => '',
    'menu_name' => __('Books')

  );
  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'has_archive' => true, 
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
  ); 
  register_post_type('book',$args);
}
add_action( 'init', 'codex_custom_init' );
3
  • I was using post-thumbnail instead of thumbnail . It makes sense now . post-thumbnail adds thumbnail for the post but for custom post type one needs thumbnail Commented Jan 27, 2015 at 17:13
  • 3
    I have 'thumbnail' in my 'supports' array but I cannot save featured image in my custom post.
    – esmitex
    Commented Jun 27, 2016 at 11:31
  • 2
    @esmitex: Besides the supports part you also have to have anadd_theme_support( 'post-thumbnails') in an appropriate action or something (which the OP already had).
    – Bart
    Commented Feb 25, 2022 at 10:57
16

For custom posts, you first have to enable support for thumbnails:

add_theme_support( 'post-thumbnails' );
function theme_setup() {
    register_post_type( 'yourposttype', array(
        ...,
        'supports' => array('title', ...,'thumbnail'),
    ));
}
add_action( 'after_setup_theme', 'theme_setup' );
2
  • Worked for me perfectly but can you please explain why "add_theme_support( 'post-thumbnails' );" is necessary to add?
    – Adi
    Commented Jan 3, 2020 at 19:55
  • I'd have to read the source to be sure, but I suppose register_post_type only loads supporting code if the theme is set to support thumbnails. Commented Sep 13, 2021 at 10:19
7

You can also use add_post_type_support() to add a single feature, if you don't want to rewrite the default supports options when registering your custom post type:

add_post_type_support( 'product', 'thumbnail' );
1
  • 1
    This is the best answer by far. The use of support attribute breaks the block editor UI. Commented Oct 17, 2022 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.