Home / attachment / Display attachment thumbnail with image metadata
  • How to Display attachment thumbnail with image metadata

    display-attachment-thumbnail-with-image-metadata

    Adding this snippet within the loop of your index.php template file will display a list of all post attachments with the following metadata (Credit, Camera, Focal Length, Aperture, ISO, Shutter Speed, Time Stamp, Copyright).

    wordpress snippet : PHP

    <>
    <?php
    if($images =& get_children( 'post_type=attachment' )){
       foreach($images as $id => $attachment ){
    	   echo '<div>';
    	   echo wp_get_attachment_image( $id, 'thumb' )."<br />";
               $meta = wp_get_attachment_metadata($id);
               echo "Credit:  ".$meta[image_meta][credit]."<br /> ";
               echo "Camera:  ".$meta[image_meta][camera]."<br />";
               echo "Focal length:  ".$meta[image_meta][focal_length]."<br />";
               echo "Aperture:  ".$meta[image_meta][aperture]."<br />";
               echo "ISO:  ".$meta[image_meta][iso]."<br />";
               echo "Shutter speed:  ".$meta[image_meta][shutter_speed]."<br />";
               echo "Time Stamp:  ".$meta[image_meta][created_timestamp]."<br />";
               echo "Copyright:  ".$meta[image_meta][copyright];
    	   echo '</div>';
       }
    }
    ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    wp_get_attachment_metadata, get_children, wp_get_attachment_image, wp,
  • denny

    Thanks for the snippets!
    i’ll add it in my blog!

    have a nice xmas!

    • http://wpsnipp.com Kevin Chard

      No problem Denny, have a good one.

  • Emil Uzelac

    Thanks for the share, looks great however it shows about 200+ undefined errors when debug is on via Theme Check plugin, you might want to check that :)

    • http://wpsnipp.com Kevin Chard

      Hi Emil, thanks Ill take a look,

  • wido

    yeah! Now i’ve a reason to take link for post thumbnail 😀

  • http://twitter.com/fstopdesign Gabriel Luethje

    I get errors unless the meta values are inside of quotes, like so:

    echo ‘Camera: ‘.$meta[‘image_meta’]'[camera’].”;