How to disable WordPress’ default image sizes

Every time you upload an image, WordPress saves that image in many sizes by default. Usually it’s ok, but there are situations when we don’t really need those thumbnails (e.g.: when our theme uses custom sizes) and I think it’s much better to delete them because they occupy space on the server for nothing.

To disable default image sizes place this code in functions.php
NOTE: if you are using a child theme, place it in child theme’s functions.php

function wcr_remove_intermediate_image_sizes($sizes, $metadata) {
    $disabled_sizes = array(
        'thumbnail', // 150x150 image
        'medium', // max 300x300 image
        'large'   // max 1024x1024 image
    );

    // unset disabled sizes
    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);

Leave a Reply

Your email address will not be published. Required fields are marked *