I'm trying to go about this without the use of a plugin, but actions and filters
Is there a way to remove extra image sizes generated by WordPress based on the Custom Post Type? I've been trying to work with the intermediate_image_sizes_advanced
filter but it doesn't look like it has access to $post
or post_type
. So I'm using the function like so:
function filter_image_sizes($sizes) {
global $post;
global $post_type;
if($post->post_type == 'cpt_slides' || $post_type == 'cpt_slides'){
unset( $sizes['thumbnail']);
unset($sizes['medium']);
unset( $sizes['large']);
}
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'filter_image_sizes');
The Reasoning / Situation
I've created a Slides Custom Post Type (like an Image Slider) that uses the Featured Image to allow the user to upload "Slides". I also have a few custom image sizes, but one specifically for the slides alone. Since the slide images are going to be one static size, I don't want WordPress to generate all these extra image sizes I'll never use, hence the question.