zartgesotten
8/3/2017 - 9:56 AM

Add post thumbnail as background-image to any div

Add post thumbnail as background-image to any div

<?php
add_action( 'wp_head', 'vr_set_featured_background', 99);
function vr_set_featured_background() {
	$image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full, false );
	if ($image_url[0]) {
	?>
		<style>
		#single-post-heading-bg {
			background:linear-gradient(rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.35)), rgba(0,0,0,0.35) url(<?php echo $image_url[0]; ?>) no-repeat center; 
			background-size: cover;
			padding: 100px 0;
		}
			#single-post-heading-bg h1, 
			#single-post-heading-bg p {
			color: #fff;	
			}
		/* Uncomment if the image hangs low in a Genesis theme */
		/*.site-inner {
			padding-top:0!important;
			padding-bottom:0!important;
		}*/
		</style>
	<?php
	}
}
?>