How to disable generation of default image sizes for some custom post types?

I think the only solution you have at the moment is to disable all intermediate image sizes:

add_filter( 'intermediate_image_sizes', '__return_empty_array', 99 );

And then manually generate them, depending on the post type, by hooking into ‘wp_generate_attachment_metadata’, where you do have access to the attachment id (and therefore to it’s parent post):

function do_your_stuff( $data, $attachment_id ) {
  // generate intermediate images

  return $data;
}

add_filter( 'wp_generate_attachment_metadata', 'do_your_stuff', 10, 2 );

Leave a Comment