Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Get the Post Thumbnail URL in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Get the Post Thumbnail URL in WordPress

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.

$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.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Mohan Krishna says:

    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.

  2. TracyDempsey says:

    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!

  3. Wynand says:

    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

  4. pipo gorosito says:

    Dude, I love you

  5. Kevin Donnigan says:

    Awesome!! Thanks for this :-) Needed it for a custom loop with a sticky post on top and set the background image.

  6. abhay says:

    Thank that help me a lot

  7. Philipp says:

    thank you man!

  8. Thiago Miro says:

    Thanks, this solved a big problem.

  9. salem says:

    that’s work thanks .

  10. Claire says:

    Perfect, thank you :)

  11. Luís Fernando Guedes says:

    Thanks for sharing!

  12. Nicola says:

    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=”” />

  13. Josh says:

    Really great article. Thanks.

  14. Jotpreet Singh says:

    Hey, Syed. Good that it’s a turn away from using plugins all the time. Well, Cheers to that

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.