Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 1 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

 
discard

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.