For a custom plugin i am using WP’s media-uploader. How can i alter the amount of different image sizes being stored? At the moment the theme uses 5 different image sizes and for my plugin i only need 2 store two image sizes?
Regards,
For a custom plugin i am using WP’s media-uploader. How can i alter the amount of different image sizes being stored? At the moment the theme uses 5 different image sizes and for my plugin i only need 2 store two image sizes?
Regards,
Comments are closed.
Additional image sizes for uploaded images are created by
wp_generate_attachment_metadata()
after the file has been uploaded. An array of available sizes is populated usingget_intermediate_image_sizes()
(thumbnail, medium, large + custom sizes) which is later used to create the images.Both of the above functions have filters for overriding the sizes available to WordPress during this task,
intermediate_image_sizes_advanced
andintermediate_image_sizes
respectively. By hooking on the any of those filters you should be able to remove the sizes you don’t need. I would suggest usingintermediate_image_sizes
as it is executed earlier and you’ll only have to filter an array of strings (image size identifiers).Not however that it is key to only apply this filter when you are handling uploads from within your plugin, naturally, as you will otherwise end up removing images sizes from WordPress globally. Thus, don’t forget to remove the filter once you’re done with the upload. Also keep in mind that WordPress kind of expects each image to be available in every image size – if a specific size is not found for an image, you will end up with the largest one.