Last active
October 9, 2015 09:01
-
-
Save sgelob/543466382f5ced8179b9 to your computer and use it in GitHub Desktop.
Responsive attachment image as background in WordPress. Working example on my photo-blog: http://olegs.be/gallery/turin-italy/
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 // Get attachment image URLs | |
$thumb_full = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); | |
$thumb_large = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' ); | |
$thumb_medium = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium' ); | |
$thumb_url_full = $thumb_full['0']; | |
$thumb_url_large = $thumb_large['0']; | |
$thumb_url_medium = $thumb_medium['0']; | |
?> | |
<style> | |
.gallery-cover { | |
background-image: url( <?php echo $thumb_url_medium; ?> ); | |
} | |
@media all and (min-width: 768px) { | |
.gallery-cover { | |
background-image: url( <?php echo $thumb_url_large; ?> ); | |
} | |
} | |
@media all and (min-width: 992px) { | |
.gallery-cover { | |
background-image: url( <?php echo $thumb_url_full; ?> ); | |
} | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment