Skip to content

Instantly share code, notes, and snippets.

@eclarrrk
Last active February 27, 2019 21:06
Show Gist options
  • Save eclarrrk/bf1d71b82d59d5daeb9fb7c6dfd12606 to your computer and use it in GitHub Desktop.
Save eclarrrk/bf1d71b82d59d5daeb9fb7c6dfd12606 to your computer and use it in GitHub Desktop.
Snippet for creating responsive images while controlling scrset values.
<?php
$imageID = get_sub_field('img_id'); // ACF should return image ID
$size = 'full';
?>
<img
class="jetpack-lazy-image"
src="<?php echo wp_get_attachment_image_url( $imageID, '$size' ) ?>"
srcset="<?php echo wp_get_attachment_image_srcset( $imageID, '$size' ) ?>"
sizes=" (min-width: 1400px) 800px,
(min-width: 860px) 60vw,
100vw"
alt="<?php echo get_post_meta($imageID, '_wp_attachment_image_alt', true); ?>"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment