Image Metadata in WordPress

WordPress saves some meta data of the uploaded images, as far as it is possible to extract them. I will show you how to display this infos right under the picture.

All we need is one function in functions.php:

function myMetaData($pic) {
  $html = '';
  $meta = wp_get_attachment_metadata($pic);
  if($meta) {
      $html = '<ul>';
      foreach($meta['image_meta'] as $key => $value) {
          $html .= '<li>' . $key . ': <strong>' . $value . '</strong></li>';
      }
      $html .= '</ul>';
  }
  return $html;
}

In image.php of the default theme we are inserting above the_content (Line 12) the new function:

<?php  echo myMetaData($post->ID); ?>

This is how it looks in the default theme::

WordPress Image Meta Data


3 Comments
  1. Chris says:

    This is very cool... I will need to keep this info handy - delicious here I come!!

  2. Andrew says:

    I wrote a plugin to do that a little while back. One of the users jumped in and added some extra code to format the results a little better, so you might want to take a look.

    http://www.wp-fun.co.uk/fun-with-photo-data/

  3. Michael says:

    Nice idea, Andrew!
    Yes, the results are not formatted, but i wanted to show how simple it is in WordPress to make such things.

Leave a Reply