search ]

Prevent WordPress from Creating Default Image Sizes

Every time you upload an image to the media library, WordPress saves it in several default sizes. Usually this is fine, but there are many cases where you do not need those images – for example if you use or define your own image sizes in your theme.

In such cases it makes sense to prevent WordPress from creating these images since they take up server space unnecessarily. To remove default image sizes in WordPress, add the following code to your functions.php file:

function wcr_remove_intermediate_image_sizes($sizes, $metadata) {
    $disabled_sizes = array(
        'thumbnail',
        'medium',
        'large'
    );

    foreach ($disabled_sizes as $size) {
        if (!isset($sizes[$size])) {
            continue;
        }
    
        unset($sizes[$size]);
    }

    return $sizes;
}

add_filter('intermediate_image_sizes_advanced', 'wcr_remove_intermediate_image_sizes', 10, 2);

For a broader guide on this topic, see the article on image sizes in WordPress.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo