How To Get Post Thumbnail As Background Image In WordPress

Share Now

1. Get image url in a variable

 $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );

2. Now add this in your inline CSS. For example:

<a href="" class="" style="background-image: url(<?php echo  $url; ?>);" ></a>
Picture of Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert