WordPress made it pretty easy to use featured image by introducing “post-thumbnail” support. Simply add below line to your theme’s functions.php and you’ll get a “Featured Image” section on the post edit screen where you can select and set a featured image.
The usage is also just work of one piece of code.
the_post_thumbnail() function will output the image as an image HTML.
What if you want to only use the image url instead of the html? There is no direct and obvious function to do that.
But we have another function
This function returns an ordered array with values corresponding to the (0) url, (1) width, (2) height, and (3) scale of an image attachment (or an icon representing any attachment).
So in order to get the featured image url, we’ll have to do as following within the loop.
We first check if we have a featured image, if yes, then move on to get the image url