Skip to content

Instantly share code, notes, and snippets.

@taotiwordpress
Created August 19, 2021 01:07
Show Gist options
  • Save taotiwordpress/12e4ddcca70bd320aaf8d5e2c1afab8f to your computer and use it in GitHub Desktop.
Save taotiwordpress/12e4ddcca70bd320aaf8d5e2c1afab8f to your computer and use it in GitHub Desktop.
[picture image] Responsive image, using thumbnail. #responsive #image #thumbnail #php
<?php
$photoBannerId = get_post_thumbnail_id();
$photoBannerUrlBase = wp_get_attachment_image_src($photoBannerId, 'listing')[0];
$photoBannerUrlBaseSmall = wp_get_attachment_image_src($photoBannerId, 'listing-small')[0];
if ($photoBannerId) { ?>
<picture>
<source media="(max-width: 1023px)" srcset="<?= esc_attr($photoBannerUrlBase) ?>">
<source media="(min-width: 1024px)" srcset="<?= esc_attr($photoBannerUrlBaseSmall) ?>">
<source srcset="<?= esc_attr($photoBannerUrlBaseSmall) ?>">
<img src="<?= esc_attr($photoBannerUrlBaseSmall) ?>" alt="Photo of <?php the_title(); ?>">
</picture>
<?php
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment