1

How do I get the height and width of default image sizes? I am not talking about custom image sizes, which can be retrieved from get_intermediate_image_sizes(). I want to get size attribute for 'thumbnail', 'medium', and 'large'.

Update Base on answer by Mridul Aggarwal, looks like i can do:

function get_image_size ($size) {
      return (array(get_option($size. '_size_w'),get_option($size. '_size_h')); 
}

Is this the only way?

2 Answers 2

4

If you want to get those set in the admin panel, use the function get_option. The keys are

get_option('thumbnail_size_w');
get_option('thumbnail_size_h');
get_option('medium_size_w');
get_option('medium_size_h');
get_option('large_size_w');
get_option('large_size_h');

If you want them for some specific attachment, use wp_get_attachment_image_src

0
0

If you using wp_get_attachment_image_src you can get width and height like this

<img 
    src="<?php $featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( 9999, 9999 ), false, '' ); echo $featured_image[0]; ?>"
    width="<?php echo $featured_image[1]; ?>"
    height="<?php echo $featured_image[2]; ?>" 
/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.