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
Follow WPBeginner on YouTube
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 lovers 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 »
  • abhay

    Thank that help me a lot

  • Philipp

    thank you man!

  • Thiago Miro

    Thanks, this solved a big problem.

  • salem

    that’s work thanks .

  • Claire

    Perfect, thank you :)

  • Luís Fernando Guedes

    Thanks for sharing!

  • Nicola

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

  • Josh

    Really great article. Thanks.

  • Jotpreet Singh

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