Different thumbnails sizes for different custom post types, and creating thumbnails for featured images only

I’ve got a wordpress site with a few custom post types. Each custom post type shows a list page, basically displaying a featured image and a title, and then you can click through to a detail page with a bunch more images.

I only need to resize uploaded “feature images”. If an uploaded image isn’t used as a feature image, I don’t need a thumbnail for it. Furthermore, each custom post type shows a different sized feature image.

Read More

So, what I want to do is say:

a) Only create thumbnails for feature images

b) Create certain sizes for certain post types, and not for others.

Is this possible? At the moment, EVERY uploaded image is getting 5 thumbnail sizes, and my wp-content directory is WAAAY bigger than it needs to be!

Thanks in advance.

Related posts

Leave a Reply

2 comments

  1. Ok I found a solution using the intermediate_image_sizes filter hook. Place this code in your functions.php and replace the ‘post_type’ and ‘img_size_name’ with the names of your post and desired image size.

    add_filter( 'intermediate_image_sizes', function($sizes){
        $type = get_post_type($_REQUEST['post_id']);
        foreach($sizes as $key => $value){
            if($type=='post_type'  &&  $value != 'img_size_name'){
                unset($sizes[$key]);
            }
        }
        return $sizes;
    });