Media library migration strategies

Migrating a site with 8,000 images from an old CMS to WordPress. The images are stored on the filesystem with a flat structure (all in one directory) and referenced by absolute paths in the content HTML.

What is the best approach to get these into the WordPress media library with proper attachment records?

do not try to import them through the WordPress admin UI. Use WP-CLI’s wp media import command. It handles the upload, generates thumbnails, and creates the attachment post records.

For 8,000 images, script it in a loop and log the mapping between old paths and new WordPress URLs. You will need that mapping to find-and-replace the image references in your content HTML.

The approach I use:

  1. rsync all images to the WordPress uploads directory in the correct year/month structure
  2. Run a script to create attachment records in the database for each file
  3. Use wp-cli to regenerate thumbnails in bulk
  4. Search-and-replace old image paths in post content using a SQL query or WP-CLI search-replace

The rsync approach is faster than importing through WP-CLI for large volumes because you skip the HTTP upload overhead. You are writing directly to disk and then registering the files.

For 8,000 images this takes about an hour total.