search ]

Get the Featured Image URL in WordPress

To enable thumbnails or featured images in posts, all you need to do is add the following line to your theme’s functions.php file:

add_theme_support('post-thumbnails'); 

It is also simple to display this image as HTML that produces the desired <img> tag:

get_the_post_thumbnail();

But what if you need only the URL of that featured image? Say when you want to use it as background-image on a specific element. It is not as simple as you might expect, but not that complicated either. What you need to do is add the following code inside the WordPress loop:

The variable $thumb_url will contain the URL of the featured image of the post in question…

For more on featured images and thumbnails, see Image Sizes in WordPress.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo