X

How to Display Attachment Thumbnail with Image Metadata

Snippets by IsItWP

Are you looking for a way to display attachment thumbnail with image metadata? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display attachment thumbnail with image metadata.

Adding this snippet within the loop of your 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).

Instructions:

All you have to do is add this code to your theme’s index.php file:

<?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>';
   }
}
?>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 27 best WordPress themes for affiliate marketing and how to set up Google Analytics eCommerce tracking for WooCommerce.

Comments   Leave a Reply

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

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

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

  3. 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 🙂

    1. Hi Emil, thanks Ill take a look,

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

    have a nice xmas!

    1. No problem Denny, have a good one.

Add a Comment Cancel reply

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!