There are always a group of our readers who are trying to graduate the beginner level early and step into WordPress development. Many of them start by hacking their WordPress themes, creating child themes, or writing plugins. This makes them come across puzzling challenges. One such reader recently asked us how to get the post thumbnail URL in WordPress. The goal here is to just get the post thumbnail URL and then use it with their own markup. In this article, we will show you how to get the post thumbnail URL in WordPress.
Note: You must know the basics of how WordPress themes work.
Simply paste this code inside the loop code that you are writing.
<?php $thumb_id = get_post_thumbnail_id(); $thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true); echo $thumb_url[0]; ?>
Make sure to replace thumbnail-size
to whatever image size you want to get. Default sizes are thumbnail, medium, large, and full. You can also use add and use additional image sizes. If you are using a custom image size then make sure to regenerate thumbnails. You can also set a default fallback image for post thumbnails.
What this code does is that we first get the post thumbnail ID. Then we use that id to get the image path or URL using wp_get_attachment_image_src
function, which returns an array that you can use with your own code.
We hope this article helped you learn how to get post thumbnail URL in WordPress. For feedback and questions, please leave a comment below.
I have designed a website using wordpress. Currently featured image is showing description section.
But i want to show featured image url in rss feed.
How to add featured image (media:thubnail) url in rss feed?
Please help…
Hi Kiran,
Please see our guide on how to add featured images to RSS feed.
WP Beginner, your second wordpress codex!
Your Site is giving awesome tips but i suggest you to provide demos of the respective codes how it looks like after making the changes as you said because users like me can have a look over that and find if it suits best or not also by the way your visitors can increase by double.
Hi there, I’m searching for how to manually get the URL, but keep finding posts with code for fetching the URL. I’m using Thesis, and I’ve used the WordPress image editor on some post images to create a cropped, square thumbnail image for my category pages’ excerpts/teasers. But, when I paste the image URL into Thesis’ thumbnail URL field, it doesn’t recognise the cropped thumbnail, but crops the original image (thereby skewing the aspect ratio). So I’m just trying to find the direct URL for the thumbnail of the source image – can you help?? Thanks in advance!
I dont know if this is the correct page to post this, but what i would like to do is the following:
I have many websites, I would like to display a thumbnail of each in a wordpress page, by just adding the url to that page, or some code surrounding the url
Can anybody help
Dude, I love you
Awesome!! Thanks for this
Needed it for a custom loop with a sticky post on top and set the background image.
Thank that help me a lot
thank you man!
Thanks, this solved a big problem.
that’s work thanks .
Perfect, thank you
Thanks for sharing!
Thanks for writing this tutorial, i don’t know why but the code you wrote never worked for me, and i know it is even available in the codex, i tried it with several loop configurations but no luck.
Recently i managed to make it work by using it in conjunction with another function: get_post_thumbnail_id()
ID ) );
?>
<img src="” alt=”” />
Really great article. Thanks.
Hey, Syed. Good that it’s a turn away from using plugins all the time. Well, Cheers to that