Instantly share code, notes, and snippets.

Embed
What would you like to do?
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