Last Updated: February 25, 2016
·
1.401K
· primus202

Fetch Featured Wordpress Post Image

You can use the following block in your template file's main post loop or any post loop. Likewise, you can replace $post->ID with a specific post ID to retrieve a particular posts featured image

<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')">

</div><?php endif; ?>