Revision 344 is a pre-publication revision. (Viewing current revision instead.)

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: [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'); [/php]

Revisions

  • January 22, 2013 @ 02:37:41 [Current Revision] by PeterLugg
  • January 22, 2013 @ 02:36:06 by PeterLugg

Revision Differences

January 22, 2013 @ 02:36:06Current Revision
Content
 Added: Taken from <a href="http:// www.studiograsshopper.ch/ code-snippets/ remove-wordpress- defaultmedia- image-sizes/" target="_blank">Studio Grasshopper</a>.
 Added: This post is in response to a question that has cropped up a couple of times in the Comments of my <a href="http:// www.studiograsshopper.ch/ web-development/wordpress- featured-images-add_image_ size-resizing- and-cropping- demo/">WordPress Featured Images – add_image_size() resizing and cropping demo</a> article.
 Added: The question? How to stop WordPress from creating default image sizes namely, the thumbnail, or medium, or large image sizes?
 Added: 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<a href="http:// www.studiograsshopper.ch/ web-development/wordpress- featured-images-add_image_ size-resizing- and-cropping- demo/">WordPress Featured Images – add_image_size() resizing and cropping demo</a> article.
 Added: 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 &gt; Settings &gt; 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.
 Added: Add the below code to your theme’s functions.php:
 Added: [php]
 Added: /**
 Added: * Remove standard image sizes so that these sizes are not
 Added: * created during the Media Upload process
 Added: *
 Added: * Tested with WP 3.2.1
 Added: *
 Added: * Hooked to intermediate_ image_sizes_advanced filter
 Added: * See wp_generate_attachment_metadata( $attachment_id, $file ) in wp-admin/includes/image.php
 Added: *
 Added: * @param $sizes, array of default and added image sizes
 Added: * @return $sizes, modified array of image sizes
 Added: * @author Ade Walker http://www.studiograsshopper.ch
 Added: */
 Added: function sgr_filter_image_sizes( $sizes) {
 Added: unset( $sizes['thumbnail']);
 Added: unset( $sizes['medium']);
 Added: unset( $sizes['large']);
 Added: return $sizes;
Deleted: Added: }
 Added: add_filter('intermediate_ image_sizes_advanced', 'sgr_filter_image_sizes');
 Added: [/php]

Note: Spaces may be added to comparison text to allow better line wrapping.

Tags: ,

No comments yet.

Leave a Reply