- Guide
- Intermediate
- 4 minutes read
- Reviewed August 5, 2026
- WordPress media
Media migration is more than copying the uploads directory.
A working WordPress asset can depend on the physical file, attachment post, post meta, generated sizes, content references, remote-storage settings, CDN URLs and caches.
Replacing a File
Uploading a new file normally creates a new attachment ID and URL. If existing content must continue using the same attachment, use a controlled replacement process.
A safe replacement should consider:
- File type and extension.
- Original dimensions.
- Generated sub-sizes.
- Attachment metadata.
- Existing block and custom-field references.
- Cache invalidation.
- Rollback.
Replacing a JPEG with a PDF or changing aspect ratio can break templates even if the attachment ID remains stable.
Stable URL vs Versioned URL
A stable URL simplifies external linking but can serve stale content from caches.
A versioned filename makes changes explicit and preserves history, but references must be updated. Choose according to the document or asset lifecycle.
Full-Site Migration
A complete migration normally includes:
- Database.
- Original uploads.
- Generated sub-sizes.
- Custom upload directories.
- Offload metadata and credentials.
- Domain and path changes.
- Search-and-replace for stored URLs where necessary.
- CDN and cache configuration.
Preserve serialized data by using WordPress-aware migration tools.
Attachment IDs
Content commonly references media by attachment ID, URL or both.
Importing files into a fresh site can create different IDs. A migration must either preserve the database records or maintain an old-to-new mapping and update every dependent field.
Custom fields, galleries, menus, widgets and plugin tables may store references outside post content.
Generated Image Sizes
Copy generated sizes when preserving the exact environment, or regenerate them after confirming the destination's registered sizes and image libraries.
Regeneration can create different crops or filenames if configuration changed. Test important visual components.
WP-CLI and Programmatic Imports
WP-CLI can import local files or remote URLs as attachments. Code can sideload files and generate metadata.
Automation should set titles, dates, authors, parent relationships and custom metadata deliberately. Test duplicate detection and failure recovery before processing a large library.
Verification
After migration:
- Compare attachment counts.
- Compare file counts and total bytes.
- Sample originals and sub-sizes.
- Crawl for 404 media URLs.
- Test featured images and galleries.
- Inspect responsive candidates.
- Verify PDFs, audio and video seeking.
- Check CDN status and cache headers.
- Review permissions and private downloads.
Rollback
Keep the source environment and a migration manifest until the destination is verified. A reversible DNS or storage change reduces risk.
Applying Replacing and Migrating Media Files in a Real WordPress Project
Consider the source asset, WordPress attachment record, generated files and every public use of the media. Accessibility, licensing, storage, performance and deletion safety should be reviewed together.
A connected concept is Media Metadata Explained. Reading the two together helps separate the immediate task from the wider WordPress responsibility.
A useful implementation begins by writing down the current state, the intended outcome and the evidence that will prove the change worked. This prevents a configuration screen, plugin recommendation or code snippet from becoming the entire strategy.
A Practical Example
Imagine a team making this decision for a production WordPress site. The useful question is not only “Can WordPress do this?” but “Which layer owns it, who maintains it, what data does it affect and how will we verify it after an update?”
Write the answer in operational terms. Name the content, user, setting, file, API or service involved. Then identify what should remain true if the theme changes, a plugin is replaced or the site is migrated.
Questions to Ask
- What user or system problem does this solve?
- Which WordPress layer owns the behaviour?
- What data is created or changed?
- Who may perform the action?
- What can fail, and how will that failure be visible?
- How is the result tested after updates?
- What is the migration or removal path?
Follow the Complete Media Lifecycle
A media decision begins with the source file and continues through upload, attachment metadata, generated derivatives, delivery, reuse, replacement and deletion.
Review visual quality, accessibility text, licensing, dimensions, file weight, cache behaviour and every place the asset is referenced. WordPress can track an attachment record, but it cannot always identify every use created by themes, custom fields or external systems.
Official Reference Context
The WordPress Media Library Documentation is the primary version-specific reference for this topic. Use the current documentation to verify interface labels, supported APIs and behaviour before applying instructions to a production site.
How to Verify the Result
- Check the original file, generated sizes and frontend delivery.
- Verify alternative text, captions, credits and direct-file visibility.
- Search for references before replacing or deleting the attachment.
Related Articles
- Media Metadata Explained
- Understanding the WordPress Media Library
- Media CDNs and External Storage
- WordPress Image Sizes and Thumbnails
Sources and Further Reading
Continue Learning
- Section: Media
- Previous: Media CDNs and External Storage
- Next: Finding and Removing Unused Media