WordPress Snippets at WPcustoms

Add custom image size and unset default sizes

This function adds a new custom image thumbnail size (‘thumbnail-custom’) in WordPress and disables the auto generated sizes except ‘full’ – Keep in mind that WordPress automatically generates 3 sizes for each image. This solves the problem by unsetting the default sizes. We now only have ‘full’ and ‘thumbnail-custom’ and can adjust these settings to fit our projects requirements. This will also save discspace on your server because we only generate images which are used in our theme. The ‘add media’ popup will only offer FULL and Custom Thumbnails for selection.

 * Snippet Name: Add custom image size and unset default sizes
 * Snippet URL: https://wpcustoms.net/snippets/add-custom-image-size-and-unset-default-sizes/
 * We unset the default size namings and merge our own custom sizes hooked into image_size_names_choose

// add our new image size:
add_image_size('thumbnail-custom', 300, 200); // 300px wide (and unlimited height)

// integrate it into the array and unload the default sizes
function add_custom_sizes_to_editor($sizes) {
    unset( $sizes['thumbnail']);
    unset( $sizes['medium']);
    unset( $sizes['large']);

 $custom_sizes = array(

        'thumbnail-custom' => 'Custom Thumbnails' //300x200
    if( !empty($sizes) )
        return array_merge($sizes, $custom_sizes);
        return $custom_sizes;
add_filter('image_size_names_choose', 'add_custom_sizes_to_editor');