Get the thumbnail image URL

Sometimes you only need the image URL to a thumbnail. To do this, use the wp_get_attachment_image_src function. The function returns an indexed array:

wp_get_attachment_image_src( get_post_thumbnail_id(), 'size-name')

Where size-name you can specify your specific thumbnail size. The indexed array returned by this function has the following meaning:

[0] => url
[1] => width
[2] => height

To have easy access to the URL use the PHP current function, such as:

current( wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumb-large') )

This will return index 0 of the array in one easy statement.

Bon App├ętit!

Tagged with: