Wordpress - Featured Image Meta Box not showing on custom post type

32,617

Solution 1

Thumbnails are by default disabled, the WordPress Codex explicitly states so here,

Themes have to declare their support for post thumbnails before the interface for assigning these images will appear on the Edit Post and Edit Page screens.

Make sure you have also done add_theme_support('post-thumbnails') somewhere in your theme/plugin, or that your post type is in the list of post types supplied to the above function (second argument is an optional array of post types) if you are already enabling it per post type.

It appears the "Screen options" setting for Featured post can be set to hide/show per post type. Though it's far fetched it might have been deactivated, though it should be activated by default I guess. Also try checking the return value of post_type_supports('project', 'thumbnail') to determine if the setting is actually set as intended, which would point to the issue being related to the admin section only.

The featured post meta box is added to the admin section by the follow lines of code:

if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) )
    add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low');

Perhaps you could run that if-statement in your theme/plugin and make sure it returns true as intended. In case it is, you might also want to inspect the edit page's source to see if #postimagediv is in the markup but not displaying.

UPDATE:

I just pasted the following code in at the end of functions.php of the Twenty Eleven theme, on a WordPress 3.4.2 install with no plugins activated, and it worked fine - the type showed up and I was able to see the post thumbnail meta box in the edit screen.

add_theme_support('post-thumbnails');
function setup_types() {
    register_post_type('mytype', array(
        'label' => __('My type'),
        'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
        'show_ui' => true,
    ));
}
add_action('init', 'setup_types');

Solution 2

i've got same problem. i used "custom post type ui" plugin for creating a 'portfolio' post type. i tried lot of things, but didn't work. Finally i've tried this code

add_action('init', 'my_custom_init');
    function my_custom_init() {
        // 'portfolio' is my post type, you replace it with yours
        add_post_type_support( 'portfolio', 'thumbnail' ); 
    }

it worked !! i've got this code from codex!!

Solution 3

If you're running a custom theme, that theme may have a theme_support call somewhere in its custom files that might be overriding your theme support call.

If You can track down that track down that theme's call, you can copy it to your own theme file and then add your custom post type to it.

You can put it inside a function and then use an action hook, like after_setup_theme.

here's an example of a custom theme original support call:

add_theme_support('post-thumbnails', array('slide-items','post','gallery-items','audio-items','video-items','page','event-items',

I was running a child theme off that main theme and needed a custom post type called 'staff'. Even though i declared support for that custom post type to include thumbnails, the featured image meta box wasn't showing.

I added the following code to my child theme functions.php file. Notice, I added 'staff' at the end of the function.

add_action( 'after_setup_theme', 'add_theme_support' );

function add_theme_support (){
    add_theme_support('post-thumbnails', array('slide-items','post','gallery-items','audio-items','video-items','page','event-items','staff'));
    }

Hope that helps.

Solution 4

I realize this is an older question, but none of these solutions worked for me. It turned out there were two problems, first: multiple plugins trying to call add_theme_support. The second was that they assumed certain types, or needed knowledge of the theme when adding support.

In the following code snippet I am safely first determining what the theme support is, and then adding my custom type to the list. By doing this in your plugin it will be compatible with other friendly themes or plugins. In fact I think a safe_add_theme_support would be nice. Anyway, I hope this helps someone and saves them from a frustrating evening.

$currentPostThumbnails = get_theme_support('post-thumbnails');
if(is_array($currentPostThumbnails)) {
    add_theme_support( 'post-thumbnails', array_merge($currentPostThumbnails, array( 'mytype' )) );
}else{
    add_theme_support( 'post-thumbnails', 'mytype');
}
Share:
32,617
Ashley Staggs
Author by

Ashley Staggs

I create websites, apps, games and do vfx and music

Updated on July 05, 2021

Comments

  • Ashley Staggs
    Ashley Staggs almost 3 years

    I just created a custom post type, but for some reason the Featured Image meta box isn't showing up.

    It does show on the "posts" post type though.

    I have enabled theme support for thumbnails and have added the following code in my custom post type code.

    <?php
    
    function register_cpt_product() {
    
        $labels = array( 
            'name' => _x( 'Products', 'product' ),
            'singular_name' => _x( 'Product', 'product' ),
            'add_new' => _x( 'Add New', 'product' ),
            'add_new_item' => _x( 'Add New Product', 'product' ),
            'edit_item' => _x( 'Edit Product', 'product' ),
            'new_item' => _x( 'New Product', 'product' ),
            'view_item' => _x( 'View Product', 'product' ),
            'search_items' => _x( 'Search Products', 'product' ),
            'not_found' => _x( 'No products found', 'product' ),
            'not_found_in_trash' => _x( 'No products found in Trash', 'product' ),
            'parent_item_colon' => _x( 'Parent Product:', 'product' ),
            'menu_name' => _x( 'Products', 'product' ),
        );
    
        $args = array( 
            'labels' => $labels,
            'hierarchical' => false,
            'description' => 'Allows the user to create products',
            'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'show_in_nav_menus' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'has_archive' => true,
            'query_var' => true,
            'can_export' => true,
            'rewrite' => true,
            'capability_type' => 'post'
        );
    
        register_post_type( 'product', $args );
    }
    
    add_action( 'init', 'register_cpt_product' );
    
    ?>
    

    The weird thing is, that on the pages which lists my entries for my post type, there is a column called Thumbnail.

    enter image description here

    Anyone know what is going on?

    Thanks

  • Ashley Staggs
    Ashley Staggs over 11 years
    I said in my question that I have enabled theme support for thumbnails already, so that is not it.
  • Simon
    Simon over 11 years
    Sorry, I must have missed that. Does it make any difference if you run add_post_type_support('your-type', 'thumbnail'); after registering the post type?
  • Ashley Staggs
    Ashley Staggs over 11 years
    I'll try that in a few minutes. In the mean I have updated my question with something strange. Thanks
  • Ashley Staggs
    Ashley Staggs over 11 years
    I have also checked the screen options a thousand times and no luck :(
  • Ashley Staggs
    Ashley Staggs over 11 years
    and adding add_post_type_support doesn't change anything
  • Simon
    Simon over 11 years
    The fact that there's a thumbnail column in your post list is a bit weird. I've never seen that in WordPress. Might it be added in there by a plugin?
  • crowjonah
    crowjonah over 11 years
    Sounds like something's wrong with your register_post_type. Can you show us the rest of it?
  • Ashley Staggs
    Ashley Staggs over 11 years
    I have added my entire custom post type code and have added a couple of screenshot of what is going on.
  • Aurovrata
    Aurovrata almost 6 years
    it was probably temporarily fixed when you initially re-installed WP which by default loads the WP theme, but your issue is likely due to your custom theme not declaring theme support.