Thursday, October 18, 2012

Display EXIF metadata in media library admin column

Adding this snippet to the functions.php of your wordpress theme will create a new column within the media library that will display EXIF metadata. Including, (credit, camera, focal length, aperture, iso, shutter speed, timestamp, copyright).

add_filter('manage_media_columns', 'posts_columns_attachment_exif', 1);
add_action('manage_media_custom_column', 'posts_custom_columns_attachment_exif', 1, 2);
function posts_columns_attachment_exif($defaults){
    $defaults['wps_post_attachments_exif'] = __('EXIF');
    return $defaults;
}
function posts_custom_columns_attachment_exif($column_name, $id){
        if($column_name === 'wps_post_attachments_exif'){
           $meta = wp_get_attachment_metadata($id);
           if($meta[image_meta][camera] != ''){
           echo "CR:  ".$meta[image_meta][credit]."<hr />";
           echo "CAM:  ".$meta[image_meta][camera]."<hr />";
           echo "FL:  ".$meta[image_meta][focal_length]."<hr />";
           echo "AP:  ".$meta[image_meta][aperture]."<hr />";
           echo "ISO:  ".$meta[image_meta][iso]."<hr />";
           echo "SS:  ".$meta[image_meta][shutter_speed]."<hr />";
           echo "TS:  ".$meta[image_meta][created_timestamp]."<hr />";
           echo "C:  ".$meta[image_meta][copyright];
           }
    }
}

No comments:

Post a Comment