I want to differentiate the featured image from post images.
The plan is to give the Featured Image multiple sizes, but the images inside / connected to the post only needs the default sizes.
I know I can use intermediate_image_sizes
to filter what Custom Post Types get assigned to what image sizes, like so:
/** Don't Make Extra Sizes **/
function post_type_sizes( $image_sizes ){
$post_type_size_array = array('icon', 'med-thumb', 'large', 'full');
$post_image_sizes = array('thumbnail', 'medium', 'large', 'full');
if( isset($_REQUEST['post_id']) && 'cpt_test' === get_post_type($_REQUEST['post_id']) )
return $post_type_size_array;
else
return $post_image_sizes;
return $image_sizes;
}
add_filter('intermediate_image_sizes', 'post_type_sizes', 999 );
But I want to only give the Featured Image multiple custom sizes, and leave any post that gets uploaded into the TinyMCE Default Sizes (thumbnail, medium, large, full).
You could do this by filtering the meta value for
_thumbnail_id
.Recreating the thumbnails is just a case of generating and updating the attachment metadata so by regenerating whenever the featured image is changed you should get the desired effect.
This will work on upload but also when the featured image is changed. In addition it will regenerate thumbs for the old thumbnail so it’s like a normal image with the normal sizes again.
The reason for using the
add_post_metadata
andupdate_post_metadata
hooks is so that we have access to the current value before it gets updated in the database.NOTE
There’s no real difference between the add media popup for the featured image or the editor, those links just open the popup in a different state so there’s no easy way to tell which state was requested (featured image or editor) when images are being uploaded, hence the approach I’ve shown above.
UPDATE
I added a function that you could call to delete sets of generated thumbnails for an attachment. You’d call this before generating new attachment metadata. You could even filter the image sizes it removes or modify the function so you can pass them as an argument.
you can also try this