Skip to main content

WPStack

How to Find and Remove Unused WordPress Media Safely
How to Find and Remove Unused WordPress Media Safely
Mediachecker WordPress media cleanup plugin

How to Find and Remove Unused WordPress Media Safely

Learn how to identify unused WordPress media using multiple reference signals, backups, dry runs, and deletion-time verification.

An attachment with no parent is not necessarily unused. It may be a featured image, a WooCommerce gallery item, a Gutenberg block asset, a widget image, an ACF value, or a file referenced directly by URL. Deleting media based on one database column is how production sites lose images.

Mediachecker approaches cleanup as an evidence problem. It checks several independent reference signals, protects recent uploads, and verifies an attachment again immediately before deletion.

Why WordPress media ownership is difficult

WordPress stores media as attachment posts, but themes and plugins are free to reference those IDs or URLs almost anywhere. Some relationships are structured; others are serialized inside options or embedded in block markup. A reliable audit therefore needs to search relationships, content, metadata, widgets, and files rather than trusting one field.

The seven reference signals worth checking

  • Attachment parents and featured-image relationships.
  • Post meta, including WooCommerce galleries and custom-field values.
  • Gallery shortcodes and Gutenberg block JSON.
  • Full URLs, filenames, and generated image-size variants in content.
  • Widget and sidebar configuration stored in options.
  • Theme templates, template parts, PHP includes, and stylesheets.
  • Recent-upload age, which protects assets that may belong to unfinished content.

Use classification before deletion

A scan result should be treated as a review queue, not a deletion order. Filter by type and size, inspect the attachment, and confirm whether the site uses a custom storage pattern. On unfamiliar builds, export the results and ask the developer how the theme stores media before making changes.

A production-safe cleanup sequence

  • Run the first scan without changing anything.
  • Keep the recent-upload protection enabled.
  • Export the audit results as CSV for review.
  • Run a dry deletion pass and examine the proposed set.
  • Create a metadata or ZIP backup of the selected files.
  • Delete in small batches and re-check important templates after each batch.
  • Keep the activity log until the cleanup has been accepted.

Duplicates are a separate decision

Two files with the same name are not proof of duplication, and two visually similar images may serve different crops or contexts. Exact hashing can identify byte-identical files. Perceptual hashing can surface visually similar candidates. Neither should automatically decide which attachment record, metadata, or URL is safe to remove.

Where AI helps and where it does not

AI can draft alt text, categorize media, and explain why an asset appears safe or risky. It should not bypass reference checks or backups. Mediachecker keeps visual duplicate detection local and makes AI media tools optional, so administrators can use the core audit without sending images to a provider.

Install Mediachecker

  • Download the current ZIP from the Mediachecker page.
  • Install and activate it from Plugins > Add New Plugin.
  • Open Media > Mediachecker and let the initial scan finish.
  • Review Unused Media and Duplicate candidates before enabling any cleanup action.
  • Configure scheduled scans only after the first manual audit is understood.

A better cleanup target

The objective is not the smallest possible uploads directory. It is a media library whose ownership is understood and whose unnecessary files can be removed reversibly. If your theme or page builder stores references in a custom format, ask WPStack to review the integration before running a large cleanup.

Frequently asked questions

Why does a used image sometimes appear unused?

A theme or plugin may store the reference in a custom table, compressed option, generated stylesheet, or remote configuration that a standard scanner cannot interpret. Treat unexpected results as a signal to inspect the owning feature before deleting the attachment.

Should I delete every duplicate?

No. Exact duplicate files may have different attachment IDs, metadata, captions, or URLs used by existing content. Choose the canonical attachment, update references, verify the affected pages, and only then remove the redundant record and file.

How large should a cleanup batch be?

Use batches small enough to verify before moving on. The right size depends on the site, but the operating rule is simple: keep a backup, retain an activity record, and stop when the next batch would be difficult to review individually.

Can deleted attachments be restored?

Mediachecker can create metadata and ZIP backups that support restoration, but recovery is still easier when the original upload path and database record remain consistent. Test the restore process before a large production cleanup.

See the complete Mediachecker plugin details, then connect media cleanup with better image alt-text workflows and the post-release maintenance checklist.

Create a deletion manifest, not a visual guess

A media item can be absent from post content and still be used by a theme option, Elementor template, custom field, WooCommerce variation, email template, CSS file, or external integration. Before deletion, export candidate attachment IDs with filenames, URLs, upload dates, sizes, and detected references. Treat that manifest as the review queue and the rollback record.

Check the places ordinary scans miss

  • Featured images, galleries, reusable blocks, and navigation items
  • Elementor templates, global widgets, background images, and generated CSS
  • Pods or other custom-field values that store attachment IDs or URLs
  • WooCommerce product galleries and variation images
  • Theme options, widgets, email templates, and hard-coded CSS references

Use quarantine before permanent removal

Move confirmed candidates to a reversible quarantine or retain a complete backup for at least one normal publishing and sales cycle. Clear caches, regenerate builder CSS where appropriate, and crawl representative pages for broken images. Test transactional email, checkout, account screens, search results, social previews, and structured data rather than checking only the homepage.

Measure reclaimed disk space separately from performance. Removing unused files primarily improves storage hygiene and backup size; it does not automatically make front-end pages faster unless those files were being requested.