Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.