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.