Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Example of apprch-wp-srcset
* Example of using apprch_wp_srcset() within WordPress loop. For function code to paste in to functions.php file, see URL below.
* @link
* In example, browsers without
* 'srcset' image attribute support are served 'large' image in 'src'.WordPress function to
* create HTML5 image element with 'srcset' and 'sizes' attributes for JPEGs and PNGs.
* Image element returned by example:
* <img class="featured-image" alt="The image alt" srcset=" 150px, 300px, 640px, 1000px" sizes="100vw" src=" >
if (has_post_thumbnail()) :
$image_id = get_post_thumbnail_id();
$src_size = 'large';
$img_sizes = '100vw';
$class = 'featured-image';
echo apprch_wp_srcset( $image_id, $src_size, $sizes, $class );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment