Image Metadata in WordPress
September 24th, 2008 by Michael • WordPress Hacks • 3 Comments
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::

Info
- Published in WordPress Hacks
- Tags: image, meta, Theme, WordPress
- Comment feed | Trackback URL
- read: 3747 | today: 2
- leave a Comment



This is very cool... I will need to keep this info handy - delicious here I come!!
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/
Nice idea, Andrew!
Yes, the results are not formatted, but i wanted to show how simple it is in WordPress to make such things.