Resizing only featured images while uploading

I was taking a backup of my wp-content folder. But when I noticed size of uploads folder. I was astonished and each image used in my blog had 5 copies with different sizes in that folder. All these totaled to 7GB in 2 months. This way it won’t take long to fill a server storage. I have a lot of image gallery posts. I didn’t knew this that each image in wordpress is resized and kept in different sizes and thought only featured images went through resizing.

So, is there a way that wordpress only resizes featured images?

1 Answer
1

You can simply set all unused image size attributes to 0 to stop WordPress generating them. Whilst this only applies for default image sizes, you can use filters to remove them.

In general, WP stores all those sizes to generate images for in the global $_wp_additional_image_sizes. The following plugin uses a filter to remove sizes on the fly. See the debugging points to unset/export/etc. the different sizes. You’ll quickly get an overview and be able to remove what you don’t need.

<?php
defined( 'ABSPATH' ) or exit;
/* Plugin Name: Disable Image Sizes */

add_filter( 'intermediate_image_sizes_advanced', 'wpse_106463_filter_image_sizes' );
function wpse_106463_filter_image_sizes( $sizes )
{
    // Uncomment the following line to see your image sizes:
    # printf( '<pre>%s</pre>', htmlspecialchars( var_export( $GLOBALS['_wp_additional_image_sizes'], true ) ) );

    // Unset default image sizes: Simply uncomment the line
    # unset( $sizes['thumbnail'] );
    # unset( $sizes['medium'] );
    # unset( $sizes['large'] );

    return $sizes;
}

And to add custom sizes to your Size selector in the admin UI, simply use the following:

add_filter( 'image_size_names_choose', 'wpse_106463_image_size_select' );
function wpse_106463_image_size_select( $sizes )
{
       return $sizes + array(
              'custom_size_name' => 'Avatar Size',
              'full'             => 'Original size'
       );
}

Leave a Comment