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

Using a get_field('sampleImage'), how would I go about in order to get the image's width and height using the ACF plug-in? I need to be able to print out the img tag with width and height attributes because of a script.

share|improve this question
up vote 3 down vote accepted

You can get the ID for the attachment with $attachment_id = get_field('field_name');. When you have the ID you can use wp_get_attachment_metadata() to get the info associated with the image in an array. The images width and height are stored in cells named width and height.

$attachment_id = get_field('field_name');
$metadata = wp_get_attachment_metadata($attachment_id);

$width = $metadata['width'];
$height = $metadata['height'];
share|improve this answer
Thank you! If you're reading this and looking for a solution - be sure to set the return value of these fields to Attachment ID in the ACF panel. – Staffan Estberg Aug 1 '12 at 15:10

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.