WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I extract the width of an image as defined in add_image_size for use as a template variable?

For example if my theme defines the size small as add_image_size( 'small', 195, 146, true ); 195 would be the variable.

I am trying to build a dynamic mshots url.

share|improve this question
up vote 2 down vote accepted

Generally speaking, there's no need to do this. However, if it's one added using add_image_size, it will be in the $_wp_additional_image_sizes global.

global $_wp_additional_image_sizes;
echo $_wp_additional_image_sizes['small']['width'];
share|improve this answer
Thanks @Otto. It was my goal to make the mshot look like the featured image for a link post format. This worked perfectly! – mattrepublic Sep 12 '11 at 18:59

This <?php wp_get_attachment_image_src( $attachment_id); ?> should return an array of

[0] => url
[1] => width
[2] => height

Also wp_get_attachment_metadata returns the original image size and additional photo data.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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