In wordpress media library is there any way to remove original image after a resize? It seems to keep the original and I feel this wastes a lot of space.
You have to use wp_generate_attachment_metadata
filter to manipulate upload image.
Here is the code:
add_filter('wp_generate_attachment_metadata', 'txt_domain_delete_fullsize_image');
function txt_domain_delete_fullsize_image($metadata)
{
$upload_dir = wp_upload_dir();
$full_image_path = trailingslashit($upload_dir['basedir']) . $metadata['file'];
$deleted = unlink($full_image_path);
return $metadata;
}
Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
The code is tested and fully functional.
Hope this helps!
I don't know the direct answer to this and it's a good idea to keep the original image for internal wordpress plugins.
However one way you can reduce the storage and reduce cost is to use the AWS S3 Plugin: https://wordpress.org/plugins/amazon-s3-and-cloudfront/ This will require you to first setup an AWS S3 Bucket. Feel free to ask another question related to doing that if it doesn't make sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With