Seems rather easy, but there is no article I can find on the web or in Wordpress about it. How to simply display (in the current post) the full image size (of the attachment), in pixels?

thank you

1 Answer 1


The wp_get_attachment_img_src( $attachment_id ) function returns an array consisting of:

  • The URL to the img
  • width
  • height

To get the actual attachment/thumbnail/featured image ID, you want to use

$att_ID = get_post_thumbnail_id( get_the_ID() );

in the loop. Outside the loop, you would have to get the Post ID somehow to feed it in as get_the_ID() refers to the currently looped post object which isn't present there. The whole call would look like this:

$img = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ) );
    'Image size: %dpx × %dpx (%s)',
    absint( $img[1] ),
    absint( $img[2] ),
    is_bool( $img[3] ) AND $img[3]
        ? 'cropped'
        : 'uncropped',

The result would display as:

Image size: 600px × 320px

  • thanks, but it displays 0px x 0px. I'm using your code, in the loop.
    – vyperlook
    Nov 6, 2014 at 16:28
  • @whitelord How did you add that image? Is it the featured image? And have you tried it with one of the default themes and all plugins turned off?
    – kaiser
    Nov 6, 2014 at 17:35
  • the image it is a featured image, yes. I uploaded it while I was in the post, so it is attached to the post. I have no problems using other codes to call the attachment in the post, so the problem is with your code.
    – vyperlook
    Nov 6, 2014 at 18:39
  • @whitelord Please tell me the output of the following: var_dump( get_the_ID(), get_post_thumbnail_id( get_the_ID() ) ); in your loop (right before the code in the answer).
    – kaiser
    Nov 6, 2014 at 18:51
  • 1
    @whitelord Oh, dear. Then just edit the answer and fix it. This is WordPress Development at least...
    – kaiser
    Nov 7, 2014 at 1:58

Your Answer

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

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