Created
February 1, 2017 03:08
-
-
Save jaclyntan/2044e64c5105ea3bc38356856f51d934 to your computer and use it in GitHub Desktop.
WordPress img srcset
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 | |
$id = get_post_thumbnail_id(); | |
$size = 'medium'; | |
$img_src = wp_get_attachment_image_url( $id, $size ); | |
$img_srcset = wp_get_attachment_image_srcset( $id, $size ); | |
$title = get_post($id)->post_title; | |
$alt = get_post_meta($id, '_wp_attachment_image_alt')[0]; | |
?> | |
<img src="<?php echo esc_url( $img_src ); ?>" | |
srcset="<?php echo esc_attr( $img_srcset ); ?>" | |
sizes="(min-width: 768px) 500px, 100vw" | |
alt="<?php echo $alt; ?>" | |
title="<?php echo $title; ?>" | |
class="feature"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment