Created
August 19, 2021 01:07
-
-
Save taotiwordpress/12e4ddcca70bd320aaf8d5e2c1afab8f to your computer and use it in GitHub Desktop.
[picture image] Responsive image, using thumbnail. #responsive #image #thumbnail #php
This file contains hidden or 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 | |
$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