Skip to content

Instantly share code, notes, and snippets.

@AaronRutley
Created December 31, 2015 23:21
Show Gist options
  • Save AaronRutley/f20a861f6016f009b25a to your computer and use it in GitHub Desktop.
Save AaronRutley/f20a861f6016f009b25a to your computer and use it in GitHub Desktop.
ar_responsive_image
<?php
function ar_responsive_image($image_id,$image_size,$max_width){
// check the image ID is not blank
if($image_id != '') {
// set the default src image size
$image_src = wp_get_attachment_image_url( $image_id, $image_size );
// set the src set with various image sizes
$image_srcset = wp_get_attachment_image_srcset( $image_id, $image_size );
// generate the markup for the responsive image
echo 'src="'.$image_src.'" srcset="'.$image_srcset.'" sizes="(max-width: '.$max_width.') 100vw, '.$max_width.'"';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment