Camera Details Box for Photos
Adds a "Camera details" box to the media edit screen showing the camera, lens settings, ISO, shutter speed, focal length and date taken that WordPress read from the photo.
Opens WPIDE on
Code
add_action( 'add_meta_boxes_attachment', function ( $post ) {
if ( ! wp_attachment_is_image( $post ) ) {
return;
}
add_meta_box( 'wpide-camera-details', 'Camera details', function ( $post ) {
$meta = wp_get_attachment_metadata( $post->ID );
$info = $meta['image_meta'] ?? array();
$rows = array(
'Camera' => $info['camera'] ?? '',
'Aperture' => ! empty( $info['aperture'] ) ? 'f/' . $info['aperture'] : '',
'Shutter speed' => ! empty( $info['shutter_speed'] ) ? ( $info['shutter_speed'] < 1 ? '1/' . round( 1 / $info['shutter_speed'] ) : $info['shutter_speed'] ) . ' s' : '',
'ISO' => $info['iso'] ?? '',
'Focal length' => ! empty( $info['focal_length'] ) ? $info['focal_length'] . ' mm' : '',
'Taken' => ! empty( $info['created_timestamp'] ) ? wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), (int) $info['created_timestamp'] ) : '',
'Copyright' => $info['copyright'] ?? '',
);
$rows = array_filter( $rows, 'strlen' );
if ( ! $rows ) {
echo '<p>No camera data stored for this image.</p>';
return;
}
echo '<table class="widefat striped"><tbody>';
foreach ( $rows as $label => $value ) {
printf( '<tr><th scope="row">%s</th><td>%s</td></tr>', esc_html( $label ), esc_html( $value ) );
}
echo '</tbody></table>';
}, 'attachment', 'side', 'low' );
} );
Notes
Only shows values that were in the file at upload time; photos stripped of metadata show nothing.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.