How To Strip WordPress Image EXIF Data To Improve Performance
If you’ve been working with WordPress for a while, chances are you’ve heard the term “EXIF data”. But what exactly is it, and why does it matter for your WordPress website?
In this article, we’re going to take a detailed look at WordPress image EXIF data, how it impacts your site, and how to manage it.
We’ll also discuss why tools like ShortPixel Image Optimizer can help you strip unnecessary metadata, making your images more efficient for the web.
Quick Takeaways
- EXIF data is image metadata storing details like camera settings and location, often unnecessary for WordPress websites.
- Removing EXIF improves site performance (by reducing file sizes), and protects privacy.
- WordPress retains metadata like alt text and captions but doesn’t natively remove EXIF.
- Use plugins like ShortPixel Image Optimizer or custom code to strip EXIF data during uploads.
What is image metadata?
Before we dive into the WordPress specifics, let’s first cover the basics: what is image metadata?
Image metadata is additional information stored within an image file, offering details beyond just the visual content. It includes various types of data, one of the most common being EXIF (Exchangeable Image File Format), which contains technical information about the image, such as camera settings and location data.
In a nutshell, image metadata is a collection of data that can help describe, sort, and even trace the origins of the image.
While this metadata has benefits, like helping organize large photo collections or protecting copyright, it also has its downsides, especially in the context of WordPress websites.
For a fun test, you can try uploading one of your images to Jimpl. You’ll be able to see exactly how much EXIF data is stored in your file and what kind of information could become public if you upload it to your website.
For example, in one of my images, metadata took up 1.07 MB (24.5%) of the file size and even included location data.
Why should you care about WordPress EXIF data?
When you upload images to WordPress, the images are stored along with all their associated metadata, including EXIF data.
While metadata like alt text, captions, and descriptions are useful for improving SEO and accessibility, the EXIF data is often unnecessary for website use.
We outlined the performance implications in a separate article, and below are a few reasons why managing image metadata is important:
❌ Page load speed: Every kilobyte counts when it comes to page speed. EXIF data, while relatively small, can add up across dozens or hundreds of images. And, as you know, faster websites are more user-friendly and rank better in search engines.
❌ Privacy concerns: EXIF data can include GPS coordinates, which means if you’re uploading photos from your smartphone, your location data might be inadvertently published.
❌ SEO benefits: Optimizing image metadata, like alt text, file names, and descriptions, can significantly improve your site’s SEO performance.
❌ Image optimization: Removing unneeded metadata can help reduce image size, especially when paired with other compression strategies.
Now that we understand what image metadata is and why it matters, let’s look into how WordPress handles it by default.
How WordPress handles image metadata
When you upload an image to the WordPress media library, the platform automatically generates multiple versions of the image in different sizes (thumbnail, medium, large, etc.) to accommodate various layout needs. Along with the visual content of the image, WordPress also retains much of the metadata embedded in the image.
WordPress natively allows you to manage certain types of metadata like the image title, alt text, caption, and description, all of which you can edit directly from the media library.
- Alt text: Alt text describes the image’s content for screen readers and search engines. Always make sure to use descriptive, keyword-optimized alt text for better accessibility and SEO.
- Caption: The caption is displayed below the image on the front end of your site and provides additional context for your visitors.
- Title and description: While not as commonly visible, these fields allow you to organize and describe your images more effectively in the backend.
Unfortunately, WordPress doesn’t provide a native method to manage or remove EXIF data. This is where plugins or custom solutions come into play.
What you need to know about WordPress image EXIF data
EXIF data is especially detailed, storing information like:
- Camera settings: Including exposure time, aperture, ISO, and flash usage.
- Date and time: When the image was taken.
- Location: GPS coordinates, which are automatically added by most smartphones and some cameras.
While this information might be useful for photographers, it’s mostly irrelevant for website visitors. In fact, including this data can slow down your site and compromise your privacy.
Here are some reasons you may want to consider removing EXIF data from your WordPress images:
❌ File size bloat: EXIF data adds a few kilobytes to each image file. While that might not seem like much, on a page with multiple images, it can add up and negatively affect load times.
❌ Privacy risks: If your EXIF data includes GPS coordinates, you might be unintentionally sharing sensitive information with your audience. This is especially relevant if you’re running a personal blog or uploading photos from your smartphone.
❌ No real SEO benefit: Google does not use EXIF data for ranking purposes. While alt text, file names, and captions are useful for SEO, EXIF data isn’t something you need to worry about keeping for better search rankings.
Given these issues, it’s generally best practice to remove EXIF data unless you specifically need it for your site (e.g., photography portfolios where camera settings are relevant).
How to remove EXIF data in WordPress
If you’re ready to optimize your WordPress images and remove unnecessary EXIF data, one of the most user-friendly solutions is ShortPixel Image Optimizer.
Our plugin not only strips unwanted metadata but also compresses and optimizes your images, which can help you speed up your site and improve your SEO.
Use ShortPixel to remove EXIF data
- Install and activate the Plugin: You can install the plugin directly from your WordPress dashboard by going to Plugins > Add New Plugin, searching for “shortpixel”, then installing and activating it.
- Configure settings: Once the plugin is activated, go to Settings > ShortPixel. Here, you can request an API Key, and then proceed to configure how you want your images to be optimized. Under the “General” tab, make sure the option to Remove EXIF data is enabled.
- Bulk optimize images: If you have a lot of images already uploaded, you can go to the Media > Bulk ShortPixel section to optimize all your images at once. This will automatically remove the EXIF data for all the images processed.
For new images that you upload, ShortPixel will automatically optimize and strip EXIF data from new images as you upload them.
Add a function to your theme files
To strip EXIF data from images upon upload in WordPress, you can also add a custom PHP function within your theme’s functions.php
file (Appearance > Theme File Editor > functions.php ).
The function will hook into the image upload process, removing the EXIF data from uploaded images.
function remove_exif_metadata_from_images($file) {
// Ensure the file exists
if (!file_exists($file['file'])) {
return $file;
}
// Check if the file is a JPEG image
$file_type = wp_check_filetype($file['file']);
if ($file_type['ext'] === 'jpg' || $file_type['ext'] === 'jpeg') {
$image_path = $file['file'];
// Attempt to create an image resource from the uploaded file
$image = @imagecreatefromjpeg($image_path);
if ($image !== false) {
// Re-save the image to strip EXIF metadata
$quality = apply_filters('jpeg_quality', 80, $image_path); // Allow quality adjustments via filter
imagejpeg($image, $image_path, $quality); // Save with specified quality
imagedestroy($image); // Free memory
} else {
error_log('Failed to create image resource for EXIF stripping: ' . $image_path);
}
}
return $file;
}
add_filter('wp_handle_upload', 'remove_exif_metadata_from_images', 10, 1);
Here is an explanation on how the snippet above works:
- The function first checks if the uploaded file exists. If it doesn’t, it simply returns without doing anything.
- It checks if the uploaded file is a JPEG image (as EXIF data is typically found in JPEGs).
- If it’s a JPEG, the function attempts to load the image into memory using
imagecreatefromjpeg()
. - The image is then re-saved using
imagejpeg()
, which strips EXIF metadata. The80
in the function represents the image quality (on a scale of 0 to 100), which can be adjusted. - Finally, it frees up the memory used by the image resource with
imagedestroy()
. - The function returns the modified file for further handling by WordPress.
Conclusion
Managing image metadata might seem like a small detail in the grand scheme, but it can have a big impact on performance, privacy, and SEO.
By understanding what data is being stored in your images, you can make informed decisions about what to keep and what to remove.
EXIF data, in particular, is one aspect of image metadata that is often unnecessary for web use. Fortunately, plugins like ShortPixel Image Optimizer make it easy to strip this data while simultaneously compressing and optimizing your images for the web.
Whether you’re running a blog, an e-commerce store, or a portfolio site, paying attention to image metadata is a simple yet effective way to improve your site’s performance and ensure you’re putting your best foot forward in the eyes of both visitors and search engines.
Go unlimited with ShortPixel!
Optimize media files effortlessly and remove EXIF data for all your images.