WordPress.org

Make WordPress Core

Ticket #45985: 45985-regular-images.patch

File 45985-regular-images.patch, 1.4 KB (added by kjellr, 3 years ago)
  • src/wp-content/themes/twentynineteen/inc/template-functions.php

     
    132132add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );
    133133
    134134/**
     135 * Add custom `sizes` attribute to responsive image functionality for post content images.
     136 *
     137 * @since Twenty Nineteen 1.0
     138 *
     139 * @param string $sizes A source size value for use in a 'sizes' attribute.
     140 * @param array  $size  Image size. Accepts an array of width and height
     141 *                      values in pixels (in that order).
     142 * @return string A source size value for use in a content image 'sizes' attribute.
     143 */
     144function twentynineteen_calculate_image_sizes_attr( $sizes, $size ) {
     145        if ( is_admin() ) {
     146                return $sizes;
     147        }
     148
     149        $width = $size[0];
     150
     151        if ( 767 <= $width ) {
     152                $sizes = '(min-width: 768px) calc(8 * (100vw / 12) - 28px), (min-width: 1168) calc(6 * 100vw/12) - 28px), calc(100% - (2 * 1rem))';
     153        }
     154
     155        return $sizes;
     156}
     157add_filter( 'wp_calculate_image_sizes', 'twentynineteen_calculate_image_sizes_attr', 10, 2 );
     158
     159/**
    135160 * Returns the size for avatars used in the theme.
    136161 */
    137162function twentynineteen_get_avatar_size() {