W3 Mind Logo
Home » How to set featured image as background image

How to set featured image as background image


<?php
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">
	.my-bg {
	border: none;
	color: black;
 	background-image: url(<?php echo $imgURL ?>);
	}
</style>
  <?php
}//end if
?>

About Author
W3Mind

W3Mind

W3Mind focuses on Blogging, Make Money Online, SEO, Business Blogging, Social Media, WordPress, Internet Tools, Web Design and Development.
Give it a Share
Facebook
Twitter
LinkedIn
You May Also Like
Leave a Reply

Your email address will not be published. Required fields are marked *

How to
START A
BLOG
(step by step)
Load WordPress Sites in as fast as 37ms!