Resizing only featured images while uploading

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