Snippets Wordpress Images Wordpress

Get WordPress Thumbnail URL, Width & Height

<?php
	$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnailsize' );
	$url = $thumb['0'];
	$width = $thumb['1'];
	$height = $thumb['2'];
?>
<img class="lazy" data-original="<?=$url?>" width="<?=$width?>" height="<?=$height?>">

Simple function to get the current post’s thumbnail/featured image, but to return it as an array so you can get the thumbnail url, the thumbnail width and the thumbnail height. In the example I’m getting it to use the thumbnail with a lazyload script (specifically this one https://github.com/tuupola/jquery_lazyload).

Replace thumbnailsize with either the name of your custom thumbnail size or one of the default WordPress sizes i.e. thumb, medium or large.

Source: https://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src