How to Display Image EXIF Metadata in WordPress

How to Display Image EXIF Metadata in WordPress

WordPress is full of functionalities, and you need to know how to use that, right? Back in 2016, we have been working on a Stock Photography website for a client from Australia. That project was a hell of a job; we have integrated premium stock photo downloading facility along with photo printing functionality using WooCommerce. However, that website never went live due to some problems between the client partners, but it gave me enough room to learn lots of new things about WordPress’ capabilities. This article is about displaying the image metadata or raw EXIF data from the camera.

What is EXIF or Metadata?

Exchangeable Image File Format or EXIF is a standard that specifies the formats for images (and sounds etc.), which is mainly used by digital cameras to store the technical details about the images you take using the cameras. For example, the camera stores the used camera model, shutter speed, ISO etc details using the EXIF data.

So, How to display image metadata in WordPress?

Image metadata or the EXIF data can be displayed in WordPress templates very quickly. However, if you are using a third-party image optimiser on your WordPress blog, then make sure that the plugin should not remove the EXIF data from your uploaded images. A couple of simple lines of codes will enable your WordPress site to display the EXIF data for the images. For this article, we are assuming you want to display the EXIF or Image Metadata for the post thumbnail, however, the same code will work for all images with slight modification in the codes.

$imageID = get_post_thumbnail_id(); //This line retrives the media ID of the post thumbnail.
$imageData = wp_get_attachment_metadata($imageID); //This line retrives all the meta data for that specific image or thumbnail in an array.
$imageExif = $imageData['image_meta'];

You need to put those codes inside the loop of your single post or single taxonomy template. Once you added those lines, the WordPress template will have access to all the image metadata. Now, all you need to do is display the EXIF values. To do that, please use the following codes.

Photo Size: <?php echo $image_meta[1] ?>x<?php echo $image_meta[2] ?> px<br>
Focal Length: <?php if(!empty($image_meta2['focal_length'])){echo $image_meta2['focal_length'].'mm';}else{echo 'Not Available';} ?><br>
Equipment: <?php if(!empty($image_meta2['camera'])){echo $image_meta2['camera'];}else{echo 'Not Available';} ?><br>

All done! If you want to explore more and display some more extra data for the image, just print the $imageExif array and you will a whole lot of data such as the ISO information etc.

Tags:

Related posts

Subscribe to our Newsletter