Some wordpress plugins creates new thumbnail sizes which I don't need.

I have created a filter

add_filter( 'intermediate_image_sizes_advanced', 

// Remove default image sizes here.
function prefix_remove_default_images( $sizes ) {
    unset( $sizes['sow-carousel-default']); // 272px x 182px set by widgets for siteorigin (carousel)
    return $sizes;

to unset these new thumbnail sizes and doesn't create these images. So that works.

But the data-srcset

<img width="270" height="180" src="data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PScwIDAgMjcwIDE4MCcgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJz48L3N2Zz4=" class="attachment-post-thumbnail size-post-thumbnail lazyload wp-post-image" alt="Ballonnen met gas gevuld aan plafond" title="Ballonnen voor je huwelijk kopen" sizes="(max-width: 270px) 100vw, 270px" data-srcset="http://wpdyw.localhost/wp-content/uploads/2017/10/ballonnen-met-gas-gevuld-aan-plafond-270x180.jpg 270w, http://wpdyw.localhost/wp-content/uploads/2017/10/ballonnen-met-gas-gevuld-aan-plafond-600x400.jpg 600w, http://wpdyw.localhost/wp-content/uploads/2017/10/ballonnen-met-gas-gevuld-aan-plafond-300x200.jpg 300w, http://wpdyw.localhost/wp-content/uploads/2017/10/ballonnen-met-gas-gevuld-aan-plafond-768x512.jpg 768w, http://wpdyw.localhost/wp-content/uploads/2017/10/ballonnen-met-gas-gevuld-aan-plafond-1024x682.jpg 1024w, http://wpdyw.localhost/wp-content/uploads/2017/10/ballonnen-met-gas-gevuld-aan-plafond-770x515.jpg 770w, http://wpdyw.localhost/wp-content/uploads/2017/10/ballonnen-met-gas-gevuld-aan-plafond-272x182.jpg 272w, http://wpdyw.localhost/wp-content/uploads/2017/10/ballonnen-met-gas-gevuld-aan-plafond-110x73.jpg 110w" data-src="http://wpdyw.localhost/wp-content/uploads/2017/10/ballonnen-met-gas-gevuld-aan-plafond-270x180.jpg" />

is still looking for this dimension (in this particular case 272 x 182) and it's giving me a 404, because the image is not generated.

How can I disable this particular image from this data-srcset?

I only see how I can hide the data-srcset, but that hides them all:

add_filter( 'wp_calculate_image_srcset_meta', '__return_empty_array' );

I only want to get rid of specific thumbnails. Is that oossible??

1 Answer 1


If you look in core, that filter is applied like so:

$image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id );

Instead of using __return_empty_array you need to add a custom function to that filter to remove the srcset size you are trying to get rid of. Something like this.

function my_srcset_function($image_meta) {
    if (!is_array($image_meta)) {
        return $image_meta;
    if (!empty($image_meta['sizes']) && !empty($image_meta['sizes']['sow-carousel-default'])) {
    return $image_meta;
  • This worked. But there is one image in the data-srcset with image dimensions 110x73 which I can not find by image_size name. How can I remove that one, based on the image dimensions?
    – sat_user
    Mar 25, 2019 at 11:02
  • Either dump out the image meta and figure out what the array key for it is that way or pop into your database and check out the contents of that meta field on an attachment directly to figure out what the key is.
    – mrben522
    Mar 25, 2019 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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