ACF Responsive Image
<?php | |
$image = get_field('my_image'); | |
if( !empty($image) ): | |
// vars | |
$size = 'large'; | |
$url = $image['url']; | |
$title = $image['title']; | |
$alt = $image['alt']; | |
$img_srcset = wp_get_attachment_image_srcset( $image['id'], $size ); | |
$img_sizes = wp_get_attachment_image_sizes( $image['id'], $size ); | |
$caption = $image['caption']; | |
// thumbnail | |
$thumb = $image['sizes'][ $size ]; | |
$width = $image['sizes'][ $size . '-width' ]; | |
$height = $image['sizes'][ $size . '-height' ]; | |
if( $caption ): ?> | |
<div class="wp-caption"> | |
<?php endif; ?> | |
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" srcset="<?php echo esc_attr( $img_srcset ); ?>" sizes="<?php echo esc_attr( $img_sizes ); ?>" /> | |
<?php if( $caption ): ?> | |
<p class="wp-caption-text"><?php echo $caption; ?></p> | |
</div> | |
<?php endif; ?> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment