Remove WordPress default media image sizes

Ducati image

This post is in response to a question that has cropped up a couple of times in the Comments of my WordPress Featured Images – add_image_size() resizing and cropping demo article.

The question? How to stop WordPress from creating default image sizes namely, the thumbnail, or medium, or large image sizes?

Not quite sure what we are talking about? For everything you ever wanted to know about WordPress image handling (but were afraid to ask), please refer to my WordPress Featured Images – add_image_size() resizing and cropping demo article.

Back to our question… Although it is possible to prevent the creation of default image sizes by changing their dimension settings to ‘0’ in Dashboard > Settings > Media, these image sizes will still appear in the list of sizes in the Media Uploader. Luckily, after trawling through WordPress core files, I found a filter that we can hook into to stop any or all of these default image sizes from being created during the upload process and from being listed in the Media Uploader.

Add the below code to your theme’s functions.php:

/**
 * Remove standard image sizes so that these sizes are not
 * created during the Media Upload process
 *
 * Tested with WP 3.2.1
 *
 * Hooked to intermediate_image_sizes_advanced filter
 * See wp_generate_attachment_metadata( $attachment_id, $file ) in wp-admin/includes/image.php
 *
 * @param $sizes, array of default and added image sizes
 * @return $sizes, modified array of image sizes
 * @author Ade Walker http://www.studiograsshopper.ch
 */
function sgr_filter_image_sizes( $sizes) {
		
	unset( $sizes['thumbnail']);
	unset( $sizes['medium']);
	unset( $sizes['large']);
	
	return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'sgr_filter_image_sizes');

In the above example, I am removing ALL default image sizes. If you don’t want to remove all the default sizes, just remove the relevant unset() lines for those default sizes that you wish to keep.

Comments

  1. Hi

    Not sure if this is the same thing, but if you go to Media Settings and add 0 for each width and height setting in the image sizes, wordpress stops creating additional image sizes.

    Only the image you upload is stored in your upload folder.

    I’ve been looking for a way to associate image sizes with a custom post type but have had no success so far. Resulting to this trick and custom meta upload boxes for each custom post type.

    Dave

    • Dave,

      You are correct, but the image size still appears (though greyed out) in the list of image sizes in the Media Uploader. The method described above does both: stops the built-in size being created during upload and remove the image size from the Media Uploader list.

      I’ll update my post, though, as it was a little misleading!

      Cheers. 🙂

  2. Andy Neale says:

    Hi,

    Thanks for this tip! very handy indeed.

    I am struggling though to get it to work properly. When I add the action and add in attachment to a post, I can see it no longer creates the 3 default sizes. However, looking in the media settings page, the 3 width and height options are still there.

    Any ideas as to why this could be? using wp 3.2.1

    Thanks,
    Andy

    • Andy,

      That’s expected behaviour.

      The code prevents the actual image sizes being created, and removes these sizes from the list of sizes displayed in the Media Uploader, but it doesn’t remove/alter the Media Settings page sizes.

      • Andy Neale says:

        Hi Ade,

        Thanks for your reply. Reading it again now, I realize that you mentioned it removes it from the Media uploader not the settings page, my bad.

        Do you know of any way to remove then from the media settings page. It could be confusing for users to see the sizes there but nothing would work when they change it.

        • Frankly, no, I don’t know.

          I’m curious too, so I’ll do some digging and will post back if I find the answer.

          • Andy Neale says:

            Thanks. I also had no luck yet figuring it out yet, but will let you know if I do.

  3. Wondering if you have any info about removing CUSTOM image sizes?

    I’m trying to remove custom, not default, image sizes that I have added via add_image_size() — but I am not sure how to pass the Image-Size-Id to my removal function variables via WordPress’s add_filter() function… or if it’s even possible…

    Basically I need a way to call the filter function that has an additional variable… is that possible?

    function sgr_filter_image_sizes( $sizes, $my_custom_image_id) {
    unset( $sizes[$my_custom_image_id]);
    etc....

    Thanks!

  4. Hi,

    thanks for sharing this!
    Do you know how to remove the “full-size” option as well?
    I want to keep only one choice: my custom image size (previously set).

  5. Hello Guys.

    Whats the Media Setting to Disable 450×300 & 940×188 images? How do I Disable 450×300 & 940×188 images from being generated everytime I upload images? I’ve disabled medium & large images by entering 0 for their dimensions, however, my site is still generating 450×300 & 940×188 all the time and I cannot find a setting to disable this. It seems to me that no matter the values are for the medium & large image dimensions 0 or whatever, these 2 extra sizes are being generated. Its a waste of CPU power & Disk space, Any solutions?

  6. Hello,

    I’ve just came across this post. Very helpful, thank you.

    I was just wondering why not use the “intermediate_image_sizes” filter from get_intermediate_image_sizes() method instead? As this returns all the available sizes for the rest of WP to work with and termine img dimensions.

    I might be wrong though, but it would be good to know the reason.

    Thanks,
    Dasha

    • Hi Dasha.

      The intermediate_image_sizes_advanced filter is run after wp_generate_attachment_metadata() loops through get_intermediate_image_sizes(). Therefore, as it is a good rule of thumb to hook as late as possible, I prefer to hook in after this looping has been done.

      Of course, your method may work (I haven’t tried it) but your function will be called on each iteration of the looping mentioned earlier. Take a look at wp-admin/includes/image.php to see what I mean.

      Cheers.

  7. hi.. my WP version >> 3.5, theme >> zBench

    i tried this code but my site is still creating 2 more sizes (i mean total 3 with original)

    i also tried this >>>> the creation of default image sizes by changing their dimension settings to ’0′ in Dashboard > Settings > Media,

    but still not working..i want only one original copy which i have uploaded….

    i tried disabling all the plugins (although i don’t have any plugin which deals with images at all)
    i also tried changing my template but no luck.. 🙁

  8. Shouldn’t you remove the thumb size as well?

  9. Thanks man i’ve been searching this and i found this on your blog.

  10. It worked like a charm but please will you tell me how to remove full size thumbnail option from wordpress.

    • Whta do you mean by “full size thumbnail”? Are you referring to the “thumbnail” size or the “full” size?

      • gonzalo says:

        Great post!
        But like harjeet ask, is there a way to delete the “full” size image?
        I only want to use my custom sizes.
        Thanks

        • The full size image is the original image. So, if you delete it, all image sizes derived from the original image will be deleted too.

  11. Alice says:

    Is there a way to have this work but for just a custom post type? I would like to disable some image sizes that were added to a theme, but that are not necessary for a specific post type.

    Thanks. Great article!

    • Hi,
      No, I don’t think there is a way to do this using the filter shown in the article. You’ll have to dig into wp-admin/includes/image.php and see if there’s a way to access the ID of the post that you are editing.
      If anyone has any suggestions, chime in!

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*


× 6 = forty two