WordPress tip: Get thumbnail url

March 15, 2012 at 8:24 pm

Today, here’s a snippet that gives you the ability to extract the source of the post thumbnail image. It is super useful if you need the post thumbnail url to use in your code.

Simply paste the following code on your theme file, within the loop.

<?php
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id);
$image_url = $image_url[0];
?>

Thanks to WP Snippets for the cool tip!

Tags: