Back to blog
4 min read Export Guides

Find Duplicate Images in the WordPress Media Library

The same photo uploaded three times as office-3.webp, office-building.webp and office-3-final.webp takes three times the space, and the Media Library doesn’t tell you they are the same file. With Import Export by RockStarLab, you export the Media Library with a hash of each file. Identical files get the same hash, whatever their names, so the duplicates are easy to find in a spreadsheet.

Free: the Media Hash Index and the Media export are in the free plugin. The File Hash (MD5) column needs version 2.1.60 or newer.

How it works

The plugin reads each file and stores its MD5 hash, a 32-character fingerprint of the file’s bytes. Two files with the same bytes have the same hash, even when their names, folders and titles differ. A resized or edited copy is a different file and gets a different hash.

Step 1: Build the hash index

Open Import Export → Tools → Media Hash Index and click Start scan. The scan reads the files in small batches and doesn’t change them. Our library of 112 files was indexed in less than a minute:

Tools, Media Hash Index: 112 media files, 112 indexed, 0 without a hash, scan at 112 of 112
The hash index covers all 112 files.

New uploads get a hash automatically, so later you only need to run the scan again if files were changed on the server.

Step 2: Export the Media Library with the hash

Open Import Export → Export, choose Media and go to Select Fields. Add ID, Title, File Name, File Hash (MD5), Attached To (Post ID) and Attached Post Title, then export to Excel:

Media export Select Fields with ID, Title, File Name, File Hash (MD5), Attached To and Attached Post Title
The File Hash (MD5) column in the Media export.

Step 3: Find the duplicates

Open the file in Excel or Google Sheets. In the first empty column, count the files with the same hash; with the hash in column D, the formula in row 2 is:

=COUNTIF(D:D, D2)

Fill it down, filter the column to values greater than 1 and sort by the hash. Each group of rows is one file stored several times. Our export had 3 groups:

Spreadsheet of the export sorted by file_hash with a Copies column: office-3.webp 3 copies, two other files 2 copies each
The export sorted by hash, rows with more than one copy.
  • office-3.webp is stored 3 times. Only the original is attached to a page, Contact Us.
  • our-team.webp was uploaded again as team-photo-2024.webp for a blog post.
  • Two entries with the same file name in different year folders are the same photo, too.

Step 4: Decide what to delete

Keep one copy of each group, usually the one attached to a post or used in your content. Before you delete a copy:

  • Check where it is used. “Attached To” only shows the post the file was uploaded to. A copy can still be in the content of other posts. Search your posts for the file name, for example with an export filter Content contains the file name, as in finding posts that link to a domain.
  • Replace it first. If a post uses the copy, change the image in the post to the copy you keep.
  • Back up. Deleting a file from the Media Library deletes it from the server. Back up the site first, or ask your AI agent to start the backup.

Unattached copies that no post uses can go. To find unattached files in general, see finding unattached media.

With an AI agent

An AI agent connected to the site through the WordPress MCP Adapter (see connecting Claude Code to WordPress) can check one file against the index:

Is the media file 2050 a duplicate of another file in the library?

In our run, the agent called rsl-ie/media-check-duplicate with the attachment ID 2050 and got back that it is a duplicate of attachment 418, office-3.webp. The check reads the index and changes nothing.

FAQ

Does the scan change my files?

No. It reads the files and stores the hashes.

Does it find resized or cropped copies?

No. Only files with exactly the same bytes get the same hash. A resized, cropped or re-saved image is a different file.

Does it find duplicates of PDFs and other documents?

Yes. The hash works for every file type in the Media Library.

Will imports create new duplicates?

Import, Media Sync and Content Sync use the same index to recognize files that are already in the library, even under another name.

Get the free plugin on WordPress.org.

Dmitriy
About author

Dmitriy

WordPress Developer with 15+ years of commercial experience. Elite Author on ThemeForest and creator of custom WordPress plugins. Passionate about clean code, performance optimization, and building useful tools for the WordPress community.

JOIN THE CONVERSATION

Comments 0

Have a question or a tip to share? Leave it below.

Leave a comment

Your email address will not be published. Required fields are marked *

We store your name, email and comment to show and moderate it; your email is never published. Spam protection is provided by Cloudflare Turnstile and profile pictures by Gravatar. See our Privacy Policy.


Try the plugin with no risks!

New users get 1 month with access to all premium features. Experience the most powerful WordPress data engine today.

Download Now
Get PRO for FREE