Get Post Thumbnail URL in WordPress – How to

How to use WordPress function wp_get_attachment_image_src and pulling out the Featured image URL to apply custom image and design to your featured image.

After Uploading Featured Image in Post many of theme developers try the_post_thumbnails() to pull out featured image. If you want to stylized your image out of the box then you need post featured image Thumbnail URL. This little tutorial helps you accomplish your task without reading the documentations. Recently working with a theme we need to Get Post Thumbnail URL in order to create out of the box.

Moreover, this WP tutorial will describe How to get Featured image/thumbnail URL in WordPress. Before trying make sure you know little bit basics how WordPress theme work. To accomplish the learners level and to command on WordPress read our Mass tutorial section on WordPress have Beginners WordPress cheat sheet, Child themes making and other wp tutorials.

Part 1.  Get Post Thumbnail URL in WordPress.

<?php
 $thumb_id = get_post_thumbnail_id();
 $thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
 echo $thumb_url[0];  //....... You can remove this line and use it in image shown in use url in custom image
 ?>

Make sure to replace thumbnail-size to whatever image size you want to get.
Default sizes are
thumbnail, medium, large, and full

Part 2. How to Use URL in Custom Image:

<img src="<?php echo thumb_url[0]; ?>" alt=" my image" />

Explanation of Part 1:

In part 1 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.

Explanation of Part 2:

We just use the thumb_url[0] to echo out the image url. If you want to use image url for custom used then use the thumb_url[0]. returned by the function.

We hope you will get benefited from this simple piece of code without any confusion. If you have any confusion about how to get post thumbnail URL in WordPress. Leave a comment we will help you to get out of this confusion.

Leave a Reply

Your email address will not be published. Required fields are marked *