Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stebrech/f605c3a70d4ee8dc0f362f9fccc6a5f7 to your computer and use it in GitHub Desktop.
Save stebrech/f605c3a70d4ee8dc0f362f9fccc6a5f7 to your computer and use it in GitHub Desktop.
<?php
function penguin_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( 'Penguin800X400' === $size ) {
$attr['sizes'] = '(max-width: 767px) calc(100vw - 30px), (max-width: 991px) 469px, (max-width: 1199px) 696.5px, 414px';
}
if ( 'Penguin800X400' === $size && ( is_sticky() ) ) {
$attr['sizes'] = '(max-width: 767px) calc(100vw - 30px), (max-width: 991px) 469px, (max-width: 1199px) 696.5px, 846.5px';
}
if ( 'full' === $size && ( is_singular() ) ) {
$attr['sizes'] = '100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'penguin_post_thumbnail_sizes_attr', 10 , 3 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment