Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #493 from mor10/try/responsive-featured-images-ind…
Browse files Browse the repository at this point in the history
…ex-archive

Add sizes attribute to featured images on index and archive pages.
  • Loading branch information
allancole authored Nov 9, 2018
2 parents 301400a + 5004504 commit 0fa8716
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions inc/template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ function twentynineteen_image_filters_enabled() {
return true;
}

/**
* Add custom sizes attribute to responsive image functionality for post thumbnails.
*
* @origin Twenty Nineteen 1.0
*
* @param array $attr Attributes for the image markup.
* @return string Value for use in post thumbnail 'sizes' attribute.
*/
function twentynineteen_post_thumbnail_sizes_attr( $attr ) {

if ( is_admin() ) {
return;
}

if ( ! is_singular() ) {
$attr['sizes'] = '(max-width: 34.9rem) calc(100vw - 2rem), (max-width: 53rem) calc(8 * (100vw / 12)), (min-width: 53rem) calc(6 * (100vw / 12)), 100vw';
}

return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );

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

0 comments on commit 0fa8716

Please sign in to comment.