Sometimes you need to turn a WP template tag into a PHP variable, so you can construct a proper bit of code.
$url = get_template_directory_uri();
$link = get_the_permalink();
$title = get_the_title ();
if ( has_post_thumbnail() ) {
echo '<a href="'.$link.'">';
echo get_the_post_thumbnail( $post->ID, 'thumbnail' );
echo '</a>';
} else {
echo '<a href="'.$link.'"><img src="'.$url.'/images/blank.jpg" alt="no image"></a>';
}
NOTE: Thumbnail tag above creates the entire img HTML. Attributes can be specified as so (array would be added to above query):
$thumbnail_attr = array(
'src' => $src,
'class' => "attachment-$size",
'alt' => 'alt here',
'title' => 'title here',
);
the_post_thumbnail($image_size , $thumbnail_attr); Reference Links
https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
https://stackoverflow.com/questions/21839556/adding-thumbnail-attribute-in-wordpress
http://blog.luutaa.com/wordpress/how-to-get-thumbnail-image-src-attribute-in-wordpress/






