4

I'm building a theme in _S and using native Gutenberg blocks.

I have the following code via my functions.php file to set my image sizes:

add_theme_support( 'post-thumbnails' );
add_image_size( 'carousel', 1366, 550, true );
add_image_size( 'hero', 1366, 400, true );
add_image_size( 'large-square', 392, 340, true ); 
add_image_size( 'medium-square', 279, 314, true );
add_image_size( 'small-square', 215, 170, true );
add_image_size( 'diagram', 650 ); 
add_image_size( 'full-width', 884 ); 
add_image_size( 'half', 430 ); 
add_image_size( 'third', 279 ); 
add_image_size( 'quarter', 203 );

I also have this code to remove the default image sizes:

function remove_default_image_sizes( $sizes) {
    unset( $sizes['thumbnail']);
    unset( $sizes['medium']);
    unset( $sizes['medium_large']);
    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'remove_default_image_sizes');

When adding new images or regenerating my thumbnails via WP CLI, there are a number of generated image sizes that appear and do not recognise:

image-scaled-2048x600.jpg
image-scaled-1536x450.jpg
image-scaled-1024x300.jpg

I initially thought it could be down to the recent WordPress 5.3 update that introduced a new way to manage large images.

I tried adding this to functions.php:

add_filter( 'big_image_size_threshold', '__return_false' );

But I still get larger images that are scaled, like so:

image-scaled-2048x600.jpg

Where could WordPress be getting these image sizes from? I'm running a single plugin for the build (ACF).

13

I found the culprit!

WordPress 5.3 introduced additional image sizes which can be found via /wp-includes/media.php.

Updating my function, like so, removed the extra sizes:

function remove_default_image_sizes( $sizes) {
    unset( $sizes['large']); // Added to remove 1024
    unset( $sizes['thumbnail']);
    unset( $sizes['medium']);
    unset( $sizes['medium_large']);
    unset( $sizes['1536x1536']);
    unset( $sizes['2048x2048']);
    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'remove_default_image_sizes');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.