WordPress generates more than 3 thumbnails or image sub sizes because there are actually more than 3 standard/core image sizes in WordPress. Moreover, themes and plugins can also register custom image sizes. :)
The 6+1 standard/core image sizes
Default (4): Thumbnail, Medium, Large and Medium Large (medium_large
), but only the first three that you can configure by default at wp-admin
→ Settings → Media.
Default additional/custom sizes (2): 1536x1536
and 2048x2048
which are added internally/automatically through _wp_add_additional_image_sizes()
which uses add_image_size()
.
Scaled (with -scaled
in the image file name): Available for high-res and non-PNG images, where WordPress makes a copy of the original (BIG) image and scales it down to the threshold size which defaults to 2560 pixels.
For example, if I upload a 4K image, it generates up to 7 more copies + the original (150, 300, 768, 1024, 1536, 20148, scaled, original).
So in that case (but note that I believe you made a typo with that "20148" and it should be 2048), the 7 copies of the original image, are most likely:
- 150 — Thumbnail
- 300 — Medium
- 768 — Medium Large
- 1024 — Large
- 1536 — Core custom image size (
1536x1536
)
- 2048 — Core custom image size (
2048x2048
)
- Scaled — Core Scaled
And if you want to be sure, you can use get_intermediate_image_sizes()
to check all the registered image sizes on the site. You can also use wp_get_additional_image_sizes()
to get just the additional/custom sizes (including both the 1536x1536
and 2048x2048
added by WordPress).
In fact, you can use wp_get_attachment_metadata()
(see examples at the very bottom) to check the sizes available for an image attachment.
Non-core/Other custom image sizes
Themes and plugins can use the same add_image_size()
to register custom image sizes, so if you noticed extra sizes than the core ones (see above), then the extra sizes may have been added by the active theme or plugins on the site. E.g.
So for such custom image sizes, you can search for add_image_size or set_post_thumbnail_size in the theme or plugin files.
How to disable certain image sizes from being generated
For the 6 standard/core sizes and all other sizes added via add_image_size()
, e.g. medium_large
and 2048x2048
, you can use the intermediate_image_sizes_advanced
hook:
add_filter( 'intermediate_image_sizes_advanced', function ( $sizes ) {
// Disable the 2048x2048 size.
unset( $sizes['2048x2048'] );
// Or maybe allow specific sizes only:
/*
$allowed = [ 'thumbnail', 'medium', 'large' ];
foreach ( $sizes as $name => $size ) {
if ( ! in_array( $name, $allowed ) ) {
unset( $sizes[ $name ] );
}
}
*/
return $sizes;
} );
For the core Scaled size, you'd want to use the big_image_size_threshold
hook:
// Disable the threshold.
add_filter( 'big_image_size_threshold', '__return_false' );
// Or maybe increase it:
/*
add_filter( 'big_image_size_threshold', function () {
return 3032;
} );
*/
Either way, make sure you know what you're doing and do it properly.
Core Scaled and wp_get_attachment_metadata()
( I mentioned this in the previous revisions, so I thought I should include it here. )
For image attachments with the core Scaled image, the main width
, height
and file
items as you can see below, will point to the scaled image and not the original one. However, the original file's name is available in original_image
.
// Query an attachment with a core Scaled image.
var_dump( wp_get_attachment_metadata( 123 ) );
/* Sample output:
array(6) {
["width"]=>
int(2560)
["height"]=>
int(1440)
["file"]=>
string(25) "2020/07/hi-res-scaled.jpg"
["sizes"]=>
array(7) {
["medium"]=>
array(4) {
["file"]=>
string(18) "hi-res-300x169.jpg"
["width"]=>
int(300)
["height"]=>
int(169)
["mime-type"]=>
string(10) "image/jpeg"
}
["large"]=>
...
["thumbnail"]=>
...
["medium_large"]=>
...
["1536x1536"]=>
...
["2048x2048"]=>
...
}
["image_meta"]=>
array(12) {
...
}
["original_image"]=>
string(10) "hi-res.jpg"
}
*/
// Query an attachment without a core Scaled image.
var_dump( wp_get_attachment_metadata( 456 ) );
/* Sample output: (no original_image)
array(5) {
["width"]=>
int(1024)
["height"]=>
int(768)
["file"]=>
string(21) "2020/07/foo-image.jpg"
["sizes"]=>
array(3) {
["medium"]=>
array(4) {
["file"]=>
string(21) "foo-image-300x225.jpg"
["width"]=>
int(300)
["height"]=>
int(225)
["mime-type"]=>
string(10) "image/jpeg"
}
["thumbnail"]=>
...
["medium_large"]=>
...
}
["image_meta"]=>
array(12) {
...
}
}
*/