Do you need to get the URL of a WordPress post’s featured image?
This can be handy if you are developing your own WordPress theme or child theme, or just making tweaks to a theme that doesn’t display a featured image by default.
In this article, we’ll show you how to get the post thumbnail URL in WordPress.
Why Get the Post Thumbnail URL in WordPress?
Adding a thumbnail or featured image to the posts on your WordPress blog will make it look more appealing by adding some visual interest. You can learn more in our guide on how to add featured images or post thumbnails in WordPress.
If you want to share a post on social media, then you may need to copy the link to the featured image or some other image in the post. We show you how to do that step by step in our guide on how to get the URL of images you upload in WordPress.
However, if you developing your own theme or modifying an existing theme, then you may need to get the post thumbnail URL so you can use it with your own custom markup. In this case, you will need to add a code snippet to your theme files.
Let’s look at how to get the post thumbnail URL in WordPress.
How to Get the Post Thumbnail URL in WordPress
If you simply wanted to display the post thumbnail, then you could paste this code into the template you are working on, inside the WordPress loop.
But since you want to display the post thumbnail using your own custom markup, or use the thumbnail in your theme some other way, you’ll need to get the post thumbnail URL.
You will need to paste this code into the template instead:
This code simply displays the URL of the featured image. You can then customize the code to use the post thumbnail URL in any way you like.
You can also customize the size of the image. You’ll need to replace the word ‘medium’ with another default image size, such as ‘thumbnail’, ‘medium-large’, ‘large’, or ‘full’.
We hope this tutorial helped you learn how to get the post thumbnail URL in WordPress. You may also want to learn how to choose the best web design software, or check out our list of proven ways to make money online blogging with WordPress.