/ Published in: PHP
Using the Picturefill and our custom post thumbnails
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'responsive-small' ); $image2 = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'responsive-medium' ); $image3 = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'responsive-large' ); ?> <picture alt="Picture fill for Wordpress using post thumbnail sized images"> <!-- <source src="external/imgs/small.jpg"> --> <source src="<?php echo $image[0]; ?>"> <!-- <source src="external/imgs/medium.jpg" media="(min-width: 400px)"> --> <source src="<?php echo $image[0]; ?>" media="(min-width: 400px)"> <!-- <source src="external/imgs/large.jpg" media="(min-width: 800px)"> --> <source src="<?php echo $image2[0]; ?>" media="(min-width: 800px)"> <!-- <source src="external/imgs/extralarge.jpg" media="(min-width: 1000px)"> --> <source src="<?php echo $image3[0]; ?>" media="(min-width: 1000px)"> <!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. --> <noscript><img src="<?php echo $image2[0]; ?>" alt="Picture fill for Wordpress using post thumbnail sized images"></noscript> </picture>