| 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 | */ |
| 144 | function 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 | } |
| 157 | add_filter( 'wp_calculate_image_sizes', 'twentynineteen_calculate_image_sizes_attr', 10, 2 ); |
| 158 | |
| 159 | /** |