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; ?>
Written by Ben Chirlin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Wordpress
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#