apply_filters( ‘fallback_intermediate_image_sizes’, string[] $fallback_sizes, array $metadata )

Filters the image sizes generated for non-image mime types.

Parameters

$fallback_sizesstring[]
An array of image size names.
$metadataarray
Current attachment metadata.

Source

$fallback_sizes = apply_filters( 'fallback_intermediate_image_sizes', $fallback_sizes, $metadata );

Changelog

VersionDescription
4.7.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    By default, when you upload an image such as a png or jpeg to the media library, WordPress generates all the standard image sizes that may be used by a theme, such as ‘thumbnail’ and ‘post-thumbnail’. Including any custom sizes you may have added to your theme using add_theme_support( 'post-thumbnails' ), set_post_thumbnail_size( 250, 250, true );, add_image_size( 'small', 500, 500 );, etc.

    But when you upload an image in pdf format, by default WordPress only generates the ‘thumbnail’, ‘medium’ and ‘large’ sizes — not all the other sizes your theme may use. Here’s a quick fix for that you can put into your theme’s functions.php:

    // Note for PHP 7 or higher, uses return type declaration
    add_filter(
      'fallback_intermediate_image_sizes',
      function ( array $fallback_sizes, array $metadata ) : array {
        return array_merge( $fallback_sizes, array_keys( wp_get_registered_image_subsizes() ) );
      }, 
    10, 2 );

    WordPress also has hardcoded behavior in wp-admin/includes/image.php to override whatever you have set the ‘crop’ parameter to for ‘thumbnail’ to false. This is a bug in my opinion because if your theme depends on images being cropped to specific dimensions or aspect ratio, this overrides it for no good reason I can think of. I don’t know of any workaround for this.

You must log in before being able to contribute a note or feedback.