X

Thumbnail source

This snippet gives you the actual src of the thumbnail! Instead of printing it in an image element.

This snippet gives you the ability to extract the source of the thumbnail image.

It could be needed in a situation where the_post_thumbnail is out of place, which also adds the img tag. The following code creates a variable $image_url which you can use wherever in the document.

This code is meant to be put in an actual WordPress template file, and can be used in different loops, where you want to use the source of the individual thumbnails.

Code Snippet:

<?php
// EXTRACTING THE THUMBNAIL IMAGE SRC.
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id);
$image_url = $image_url&#91;0&#93;;
?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!