awhedbee22 of Helpful Scripts
2/12/2015 - 10:16 PM

Create header using featured image.

Create header using featured image.

<div class="headerImage"></div>

if (has_post_thumbnail()) { //if a thumbnail has been set

	$imgID = get_post_thumbnail_id($post->ID); //get the id of the featured image
	$featuredImage = wp_get_attachment_image_src($imgID, 'full' );//get the url of the featured image (returns an array)
	$imgURL = $featuredImage[0]; //get the url of the image out of the array

	<style type="text/css">
	    .headerImage {
	    	height: 275px;
	    	width: 100%;
	        background:url('<?php echo $imgURL ?>') no-repeat center center fixed; 
			-webkit-background-size: cover;
			-moz-background-size: cover;
			-o-background-size: cover;
			background-size: cover;

	}//end if