How to Get your Post Thumbnail’s Width and Height
In Settings > Media, you are able to set only the height or width of the Thumbnail images and WordPress will resize them proportionally (i.e.: if you have a fixed height, then the widths will vary depending on your uploaded image dimension, and vice versa).
Inside the loop, you can get a thumbnail’s width, height and URL using this code:
$imgdata = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail' ); $imgurl = $imgdata; // the url of the thumbnail picture $imgwidth = $imgdata; // thumbnail's width $imgheight = $imgdata; // thumbnail's height
For the second parameter of the
wp_get_attachment_image_src function you can also use ‘medium’, ‘large’ and ‘full’. They correspond to the dimension for the other sizes in Settings > Media.