Skip to content
This repository was archived by the owner on Jan 15, 2019. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions inc/template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,31 @@ function twentynineteen_post_thumbnail_sizes_attr( $attr ) {
}
add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );

/**
* Add custom `sizes` attribute to responsive image functionality for post content images.
*
* @since Twenty Nineteen 1.0
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function twentynineteen_calculate_image_sizes_attr( $sizes, $size ) {
if ( is_admin() ) {
return $sizes;
}

$width = $size[0];

if ( 767 <= $width ) {
$sizes = '(min-width: 768px) calc(8 * (100vw / 12) - 28px), (min-width: 1168) calc(6 * 100vw/12) - 28px), calc(100% - (2 * 1rem))';
}

return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentynineteen_calculate_image_sizes_attr', 10, 2 );

/**
* Returns the size for avatars used in the theme.
*/
Expand Down