Skip to content

Instantly share code, notes, and snippets.

@piperhaywood
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piperhaywood/686cc0c788bd9fc3fa6e to your computer and use it in GitHub Desktop.
Save piperhaywood/686cc0c788bd9fc3fa6e to your computer and use it in GitHub Desktop.
Example of apprch-wp-srcset
<?php
/**
* Example of using apprch_wp_srcset() within WordPress loop. For function code to paste in to functions.php file, see URL below.
* @link https://gist.github.com/piperhaywood/96ac07ea5f4999512275
*
* 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="http://your-site.com/wp-content/uploads/2014/12/your-image-150x150.jpg 150px, http://your-site.com/wp-content/uploads/2014/12/your-image-300x300.jpg 300px, http://your-site.com/wp-content/uploads/2014/12/your-image-640x640.jpg 640px, http://your-site.com/wp-content/uploads/2014/12/your-image-640x640.jpg 1000px" sizes="100vw" src="http://your-site.com/wp-content/uploads/2014/12/your-image-640x640.jpg >
*/
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 );
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment