Remove WordPress default media image sizes

Taken from Studio Grasshopper.

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 myWordPress 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');

Revisions

Tags: ,

No comments yet.

Leave a Reply