0

I am trying to find the real thumbnail size of the posts.

In my blog in the past years I was uploading images (and thumbnails) of 600px width. At the beginning they were even smaller. In the last years they are 1000px width.

I am trying to find a solution in order to correctly use the following Rich Snippets for Articles:

How can I get the real size of the thumbnail, knowing that different posts can have thumbnails of different sizes?

Is it wp_get_attachment_image_src? How to use it?

Thanks

0

wp_get_attachment_metadata - Retrieve attachment meta field for attachment ID.

$image_meta = wp_get_attachment_metadata( $attachment_id, $unfiltered );

As you can see, the width x height is nested in sizes for each size.

Array
   (
       [width] => 2400
       [height] => 1559
       [file] => 2011/12/press_image.jpg
       [sizes] => Array
           (
               [thumbnail] => Array
                   (
                       [file] => press_image-150x150.jpg
                       [width] => 150
                       [height] => 150
                       [mime-type] => image/jpeg
                   )
               [medium] => Array
                   (
                       [file] => press_image-4-300x194.jpg
                       [width] => 300
                       [height] => 194
                       [mime-type] => image/jpeg
                   )
               [large] => Array
                   (
                       [file] => press_image-1024x665.jpg
                       [width] => 1024
                       [height] => 665
                       [mime-type] => image/jpeg
                   )
               [post-thumbnail] => Array
                   (
                       [file] => press_image-624x405.jpg
                       [width] => 624
                       [height] => 405
                       [mime-type] => image/jpeg
                   )
           )
       [image_meta] => Array
           (
               [aperture] => 5
               [credit] => 
               [camera] => Canon EOS-1Ds Mark III
               [caption] => 
               [created_timestamp] => 1323190643
               [copyright] => 
               [focal_length] => 35
               [iso] => 800
               [shutter_speed] => 0.016666666666667
               [title] => 
           )
   )
  • Thank you. This would work fine. What should I put instead of XXX: <meta itemprop="width" content="<?php XXX ?>"> – Pikk Dec 17 '15 at 15:41
  • Ask that as a separate question because it's worth it's own answer. – jgraup Dec 17 '15 at 16:03
  • Be sure to include where you want to use it and what you expect the outcome to be. Also include any examples that might help and I'm sure you can get a good answer. – jgraup Dec 17 '15 at 16:15
  • Done. If you need more info, please ask, I will provide what I know. – Pikk Dec 17 '15 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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