Make WordPress Core

Changeset 46066


Ignore:
Timestamp:
09/05/2019 10:26:50 PM (5 years ago)
Author:
azaozz
Message:

Media: Add two new intermediate image sizes, 1536px and 2048px. They are meant to enhance the way WordPress displays images on the front-end on larger, high-density devices. They make it possible to generate more suitable srcset and sizes attributes, and not use the original, often non-optimized image.

Also change the default max_srcset_image_width value to match the new max size.

Props pierlo, azaozz.
See #43524.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r45901 r46066  
    520520add_action( 'wp_playlist_scripts', 'wp_playlist_scripts' );
    521521add_action( 'customize_controls_enqueue_scripts', 'wp_plupload_default_settings' );
     522add_action( 'plugins_loaded', '_wp_add_additional_image_sizes', 0 );
    522523
    523524// Nav menu
  • trunk/src/wp-includes/media.php

    r45932 r46066  
    12011201     * @since 4.4.0
    12021202     *
    1203      * @param int   $max_width  The maximum image width to be included in the 'srcset'. Default '1600'.
     1203     * @param int   $max_width  The maximum image width to be included in the 'srcset'. Default '2048'.
    12041204     * @param array $size_array Array of width and height values in pixels (in that order).
    12051205     */
    1206     $max_srcset_image_width = apply_filters( 'max_srcset_image_width', 1600, $size_array );
     1206    $max_srcset_image_width = apply_filters( 'max_srcset_image_width', 2048, $size_array );
    12071207
    12081208    // Array to hold URL candidates.
     
    43304330    );
    43314331}
     4332
     4333/**
     4334 * Add additional default image sub-sizes.
     4335 *
     4336 * These sizes are meant to enhance the way WordPress displays images on the front-end on larger,
     4337 * high-density devices. They make it possible to generate more suitable `srcset` and `sizes` attributes
     4338 * when the users upload large images.
     4339 *
     4340 * The sizes can be changed or removed by themes and plugins but that is not recommended.
     4341 * The size "names" reflect the image dimensions, so changing the sizes would be quite misleading.
     4342 *
     4343 * @since 5.3.0
     4344 * @access private
     4345 */
     4346function _wp_add_additional_image_sizes() {
     4347    // 2x medium_large size
     4348    add_image_size( '1536x1536', 1536, 1536 );
     4349    // 2x large size
     4350    add_image_size( '2048x2048', 2048, 2048 );
     4351}
Note: See TracChangeset for help on using the changeset viewer.