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.
Related articles:
- Wordpress Featured Images - add_image_size() resizing and cropping demo
- Remove WordPress default media image sizes
- WordPress - List all image sizes in Media Uploader







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.
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.
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.
Thanks. I also had no luck yet figuring it out yet, but will let you know if I do.