0

I've found several examples where they use the intermediate_image_sizes_advanced filter to unset the default WP image sizes that are generated whenever a user uploads a new image to the media library. This filter, on a brand new install with no plugins will not be called at all.

Calling get_intermediate_image_sizes() spits out the following array:

[05-Feb-2020 17:29:55 UTC] Array
(
    [0] => thumbnail
    [1] => medium
    [2] => medium_large
    [3] => large
    [4] => 1536x1536
    [5] => 2048x2048
)

Where did 1536x1536 come from? Where did 2048x2048 com from?

I later tried to call remove_image_size('size') from within an init action and this only worked for the two new sizes mentioned above. The other default sizes still remained:

[05-Feb-2020 17:30:26 UTC] Array
(
    [0] => thumbnail
    [1] => medium
    [2] => medium_large
    [3] => large
)

Does anyone know what's going on here? Has something changed?

2
  • Ive found another similar question regarding the new image sizes, apparently it's new since 5.3: wordpress.stackexchange.com/a/354379/57775. – eballeste Feb 5 '20 at 18:20
  • The accepted answer in the linked question also uses the intermediate_image_sizes_advanced filter. This filter is not working for me. – eballeste Feb 5 '20 at 18:21
2

Using the intermediate_image_sizes_advanced filter was not working for me. However, the intermediate_image_sizes works and the $default_sizes array is an indexed array, not an associative array. In every single example that I have found for using the intermediate_image_sizes_advanced filter, the answer's are unsetting the image sizes from an associative array.

The following worked for me in WP 5.3:

add_filter( 'intermediate_image_sizes', 'remove_default_img_sizes', 10, 1);

function remove_default_img_sizes( $sizes ) {
  $targets = ['medium', 'medium_large', 'large', '1536x1536', '2048x2048'];

  foreach($sizes as $size_index=>$size) {
    if(in_array($size, $targets)) {
      unset($sizes[$size_index]);
    }
  }

  return $sizes;
}

Here's a link to the function that adds the two additional sizes since 5.3 with an explanation to why I was able to remove them using remove_image_size.

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.