WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using a lot of thumbnails but never the original file. To save space, I'd like to prevent the original from being saved on disk but only keep a thumbnail of 100px. How can I do this?

Thanks, Dennis

share|improve this question
could it be an idea perhaps to not upload large images in the first place? – Piet Jun 22 '11 at 15:28
Not an option as the submissions are crowd sourced :) – FLX Jun 23 '11 at 14:03
Would a cron script that goes through and periodically deletes the originals be an option? – Joshua Aug 2 '11 at 21:07
please see my answer to the same question wordpress.stackexchange.com/questions/17719/… – Cristian Aug 3 '11 at 8:38
If you already have some images and discover this later, use this extension: wordpress.org/plugins/regenerate-thumbnails It calls the hook used in the answers by Cristian and SimonSimCity – SimonSimCity Sep 25 '13 at 11:10
up vote 9 down vote accepted
add_filter( 'wp_generate_attachment_metadata', 'delete_fullsize_image' );
function 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;
share|improve this answer
Awesome, it works! The only (minor) problem I have is that when I look at the Media Library it doesn't show images as the full images has (obviously) been deleted. Is there a way to set the thumbnail as the Media Library Icon? Example: i.imgur.com/koijq.png (top is using your method, bottom is the original without deletion) – FLX Aug 6 '11 at 14:19
If you try a cmd refresh I thought WP was clever enough to use another version. I used this method a while ago so can't remember. I'd have to play around with it. Sorry I dont have a direct answer now! – Cristian Aug 6 '11 at 17:12
If this is 'just' about deleting those giant 16 MPix images end-end-users might upload, another version might be to copy a somewhat small thumbnail into the full former name. That way, still the space is 95%ish saved, no one can access the fullres (since it's gone), yet Media Library showing will still work... (?) – Frank N Nov 23 '12 at 14:46

I foud another solution in the web. It's based on the one accepted here, but it takes it even further.

The one, accepted here, removes the main-image and goes on. The solution I found replaces the original image by the image generated for "large". It just goes on without replacing if this image-resolution is not defined.

This way it is ensured that every script, relying on the original image, will still work as before - for example the thumnail regeneration.



@dalbaeb pointed me to an issue written in the comments on the blog-post. I rewrote the code based on the API instead of the solution provided there. It's not that much of a difference, but just to use the same function calls as in the API ;)

function replace_uploaded_image($image_data) {
    // if there is no large image : return
    if (!isset($image_data['sizes']['large'])) return $image_data;

    // paths to the uploaded image and the large image
    $upload_dir = wp_upload_dir();
    $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file'];
    $large_image_filename = $image_data['sizes']['large']['file'];

    // Do what wordpress does in image_downsize() ... just replace the filenames ;)
    $image_basename = wp_basename($uploaded_image_location);
    $large_image_location = str_replace($image_basename, $large_image_filename, $uploaded_image_location);

    // delete the uploaded image

    // rename the large image
    rename($large_image_location, $uploaded_image_location);

    // update image metadata and return them
    $image_data['width'] = $image_data['sizes']['large']['width'];
    $image_data['height'] = $image_data['sizes']['large']['height'];

    // Check if other size-configurations link to the large-file
    foreach($image_data['sizes'] as $size => $sizeData) {
        if ($sizeData['file'] === $large_image_filename)

    return $image_data;
add_filter('wp_generate_attachment_metadata', 'replace_uploaded_image');


I had a problem with the code on one client where another size-configuration linked to the large-file. I updated the code accordingly. If you have any kind of problems with it, drop me a mail.

share|improve this answer
Thanks for posting an alternative! Although 1) the solution appears to be buggy as per the comments after the article; and 2) it's always good to post the code directly in the answer, as the linked article could always disappear. – montrealist Apr 5 '13 at 18:21
Thanks for the hint, @dalbaeb. I've updated my comment accordingly. – SimonSimCity Apr 5 '13 at 19:14

I just created a plugin because I had the same problem. You can download it from here

share|improve this answer
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – ialocin Sep 30 '15 at 14:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.