Created
December 31, 2015 23:21
-
-
Save AaronRutley/f20a861f6016f009b25a to your computer and use it in GitHub Desktop.
ar_responsive_image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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