| | 135 | * Add custom sizes attribute to responsive image functionality for post content images. |
| | 136 | * |
| | 137 | * @origin Twenty Nineteen 1.0 |
| | 138 | * |
| | 139 | * @param string $sizes A source size value for use in a 'sizes' attribute. |
| | 140 | * @param array|string $size Requested size. Image size or array of width and height values |
| | 141 | * in pixels (in that order). |
| | 142 | * @param string|null $image_src The URL to the image file or null. |
| | 143 | * @param array|null $image_meta The image meta data as returned by wp_get_attachment_metadata() or null. |
| | 144 | * @param int $attachment_id Image attachment ID of the original image or 0. |
| | 145 | * @param array $block_attr Attributes from the parent block. |
| | 146 | */ |
| | 147 | function twentynineteen_calculate_image_sizes_attr( $sizes, $size, $image_src, $image_meta, $attachment_id, $block_attr ) { |
| | 148 | if ( is_admin() ) { |
| | 149 | return $sizes; |
| | 150 | } |
| | 151 | |
| | 152 | $align = $block_attr[align]; |
| | 153 | if ( '' === $align ) { |
| | 154 | $sizes = '(min-width: 768px) calc(8 * (100vw / 12) - 28px), (min-width: 1168) calc(6 * 100vw/12) - 28px), calc(100% - (2 * 1rem))'; |
| | 155 | } elseif ( 'wide' === $align ) { |
| | 156 | $sizes = '(min-width: 768px) 80%, calc(100% - (2 * 1rem))'; |
| | 157 | } elseif ( 'full' === $align ) { |
| | 158 | $sizes = '100vw'; |
| | 159 | } |
| | 160 | return $sizes; |
| | 161 | } |
| | 162 | add_filter( 'wp_calculate_image_sizes', 'twentynineteen_calculate_image_sizes_attr', 10, 6 ); |
| | 163 | |
| | 164 | /** |