Home » Labs » How to get Thumbnail URL in WordPress  

How to get Thumbnail URL in WordPress

Filed under Labs

Hi everybody, here is a simple snippet which allows you to extract the source of the post thumbnail image on WordPress. It’s very useful if you need post thumbnail URL to use in your code.
Simply copy and paste the following code to your theme template. Please make sure that the code is pasted within the loop.

//  Get WordPress Thumbnail URL
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id);
$image_url = $image_url[0];

Posts you may like: