Skip to content

Instantly share code, notes, and snippets.

@thetwopct
Last active April 23, 2019 10:17
Show Gist options
  • Save thetwopct/fba73ce5141d2c41c967d279974b6714 to your computer and use it in GitHub Desktop.
Save thetwopct/fba73ce5141d2c41c967d279974b6714 to your computer and use it in GitHub Desktop.
ACF Responsive Images (srcset)
<?php
$img = the_sub_field( 'image' ); // or get_field ACF - make sure field is set to ID
$size = 'home-hero'; // thumbnail size
$src = wp_get_attachment_image_src( $img, $size );
$srcset = wp_get_attachment_image_srcset( $img, $size );
?>
<img class="pillar-image"
src="<?php echo esc_url( $src[0] ); ?>"
srcset="<?php echo esc_attr( $srcset ); ?>"
sizes="(max-width: 640px) 640px, (max-width: 1024px) 1024px, 1600px" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment