For a client project I'm working on the client wanted to ensure that all geo data and unnecessary metadata was stripped from their images when they upload them to the WordPress media library.
How WordPress VIP does it?
I first came across a solution that WordPress VIP offers their clients using the Gmagick
php extension. Since my client will be using Imagick
instead, I rewrote the functions to fit my needs. They offer two solutions, one is by adding a URL parameter to all images, but they suggest using code instead to strip metadata on upload. Learn more about how WordPress VIP handles this:
What image metadata?
We want to remove JPEG image Exif, IPTC, comment, and color data from the images uploaded to the WordPress media library.
In the code example below, we preserve the image file’s ICC color profile data (icc
) but strip all other metadata from images on upload. This code example can be modified to preserve other types of profile data, or to strip all metadata entirely upon file upload.
Code Snippet to strip image metadata
This code snippet can be added to a theme’s functions.php, or as a separate plugin.
That's it. Once in your theme or plugin, all future uploads will be stripped of their unused metadata. Please make sure this is compliant with any images you licence from third parties.