Snippets
WordPress Display Thumbnail for Post (2 Ways)
Did you ever want to make WordPress display Thumbnail for post but did not know how to do it? I am going to discuss 2 ways to do this. Just copy this snippet into your theme, wherever you want to display the thumbnail and that should do it.
Method 1:
if (has_post_thumbnail())
{
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail_name');
// This gives the thumbnail url
echo $thumb[0];
}Method 2:
<?php
if(has_post_thumbnail())
{
the_post_thumbnail();
}
?>Do you know of any better method or a new method to display thumbnail for a post in WordPress? If yes, please share it with us in your comment below.