Wordpress - How do you get the post thumbnail size?

There is however another way:

get_option( 'thumbnail_size_w' );
get_option( 'thumbnail_size_h' );

Note: thumbnail is one of the sizes set inside $_wp_additional_image_sizes. So the call to get_option() will work for every other image size too.


When an image size is added either by WordPress(add_image_size), or by a plugin or your own custom code it gets added into the $_wp_additional_image_sizes global, i can't find a similar function for pulling data from that global, but you could certainly just look inside the global to determine what width and height a registered image size has.

Example:

global $_wp_additional_image_sizes;
// Output width
echo $_wp_additional_image_sizes['post_thumbnail']['width'];
// Output height
echo $_wp_additional_image_sizes['post_thumbnail']['height'];

Of course just be sure to reference those values at a point after you've set the size. So if for example you're setting the thumbnail size during init, you'll need to make sure to do whatever you need to after that point(else you'll get back the sizes as they were prior to setting them).

Hope that helps.


The only thing still missing is the thumbnail's ID:

$post_thumbnail_id = get_post_thumbnail_id( $post_id );
$attachment = wp_get_attachment_image_src( $post_thumbnail_id );
$width=$attachment[1];
$height=$attachment[2];