Back to blog
7 min read Tutorials

Import External Images in WordPress Posts into the Media Library

Posts often show images that live on another server: an old domain you migrated away from, a staging site, a CDN you stopped paying for, or a site you copied content from. The images still load today, but they are not in your Media Library. When the other server goes away, the posts show broken images, and until then every page view depends on it. Import Export by RockStarLab fixes this with an export and a re-import: it downloads every external image in the post content into your Media Library and points the posts at the local copies.

Free: everything in this guide works in the free plugin. We tested it with Import Export by RockStarLab 2.2.13 and WordPress 7.1.

Short Answer

Export the affected posts with three columns (ID, Title, Content), using the filter Content contains the external address. Import the same file back as posts with Check for Existing Items by Field: ID, If Match Found: Update and Automatically Import Media Files turned on. The import downloads each image, attaches it to its post and replaces the address in the content.

Step 1: Find the Posts with External Images

In our test, the posts used images from http://aie6.local:10096/wp-content/uploads/, an older site. In Import Export by RockStarLab > Export we chose Blog Posts and, on the Filters step, added Content / Contains with that address. The counter shows how many posts reference it:

Export Filters step: Content Contains aie6.local:10096/wp-content/uploads, 2 items available
The Content contains filter finds the posts that use images from the other server.

Use the part of the address that all the image links share, usually the domain plus /wp-content/uploads. If images come from several servers, export once per server or leave the filter out and export every post: posts without external images are left as they are.

Step 2: Export ID, Title and Content

On the Fields step, we dragged only ID, Title and Content into the file:

Export Fields step with ID, Title and Content in the file
Three columns are enough.

Three columns are enough. The import updates only the columns in the file, so categories, dates, authors, featured images and custom fields of the posts stay as they are. The CSV we downloaded had one row per post, with the image tags in the Content column still pointing to the old server.

Step 3: Import the File Back with Media Import On

In Import, we chose Blog Posts, uploaded the CSV and let Auto Map map the three columns. The settings that matter are on the Options step:

Import Options: Check by ID, If Match Found Update, If No Match Found Skip, Automatically Import Media Files on, If Media File Already Exists Skip
Update by ID with Automatically Import Media Files on.
  • Check for Existing Items by Field: ID and If Match Found: Update: each row updates the post it came from.
  • If No Match Found: Skip: no new posts are created if an ID is missing.
  • Automatically Import Media Files: on. This is the setting that downloads the images.
  • If Media File Already Exists: Skip: when an identical file is already in your Media Library, it is reused instead of being downloaded a second time.

The import finished in two seconds and updated the post:

Import finished: 1 successful, 1 updated, 0 created, 0 skipped, 0 failed
The post was updated.

What Changed

Our test post had two images from the old server. After the import:

  • The polo shirt photo was downloaded into the Media Library as polo-navy.jpg and attached to the post (Uploaded to shows the post title).
  • The sunglasses photo was not downloaded again: the same file was already in the library under another name, sunglasses-2.jpg, and the import found it by its size and file hash and used it.
  • Both image addresses in the post now point to this site’s /wp-content/uploads/.
  • Each downloaded image got the alt text of its <img> tag in the Media Library, unless it already had alt text there.
Media Library list showing polo-navy.jpg uploaded to the post Merch Restock: Polos and Sunglasses
The downloaded image is attached to its post.

On the front end, the post looks the same as before, but both images now load from this site:

Front end of the post with a polo shirt and sunglasses images loading from this site
The post looks the same; the images now load from this site.

We ran the same import on two more posts whose images were already in the library from an earlier migration. Nothing was downloaded; the addresses were simply switched to the existing local files.

With an AI Agent or WP-CLI

The same export and re-import run without the admin screens. Through the WordPress MCP Adapter, WordPress itself gives an AI agent only read-only abilities for site, user and environment information; Import Export by RockStarLab adds the export, the upload and the import with media download, so one request is enough:

With Import Export by RockStarLab, find the posts whose content has images from old-site.example.com, export them with ID, title and content, and import the file back by ID with media import on, so the images are downloaded into the Media Library.

The agent calls rsl-ie/export-start with the filter Content contains the old address and the three fields, takes the file with rsl-ie/file-get, uploads it and runs rsl-ie/import-start with unique_field ID, update for matches, skip for the rest, auto_import_media on and duplicate media skipped. On a server, the same two steps are two WP-CLI commands:

wp rsl-ie export --type=post --fields=ID,post_title,post_content --options='{"filters":[{"field":"post_content","condition":"contains","value":"old-site.example.com/wp-content/uploads"}]}' --name=external-images --user=admin
wp rsl-ie import external-images.csv --type=post --unique-field=ID --if-exists=update --options='{"if_not_exists":"skip","auto_import_media":true,"media_duplicate_mode":"skip"}' --user=admin

We ran these commands on a test site with Import Export by RockStarLab 2.2.63. Export job 88090 found the one post with images from the other server, and import job 88091 downloaded both images into the Media Library, attached them to the post with the alt texts from the <img> tags and switched both addresses to the site’s own uploads.

Tips

  • Back up the database first. The import asks you to confirm a backup before it starts, and it is worth having one: the import rewrites post content.
  • The old server must still be reachable. The import downloads each file from its current address. If the server is already gone, bring it back at its old address for the time of the import, for example from a backup of its uploads folder; images that cannot be downloaded keep their old address.
  • Big sites: the import works in batches and continues in the next request after about 20 seconds, so hundreds of posts with many images are fine. Files that fail to download are listed in the import log with the reason, and those image addresses stay unchanged.
  • Pages and custom post types work the same way: choose Pages or your post type in both the export and the import.

FAQ

How do I import external images into the WordPress Media Library?

Export the posts with ID, Title and Content, then import the file back with Check by ID, Update and Automatically Import Media Files turned on. Every image in the content that lives on another server is downloaded and the post is updated to use the local copy.

Will this create duplicate images?

Not with If Media File Already Exists set to Skip. Before downloading, the import compares file name, size and MD5 hash with the files already in your Media Library and reuses a match.

Does it change anything else in the posts?

No. The import updates only the columns in the file. With ID, Title and Content, the only change is the image addresses in the content.

Are images from Gutenberg blocks and background images included?

Yes. Besides <img> tags, the import picks up image URLs in Image, Cover, Gallery and Media & Text blocks, CSS background images, File blocks, and audio and video files in the content.

Can an AI agent or WP-CLI do this?

Yes. The plugin gives an AI agent and WP-CLI the same export and import: export the posts with ID, title and content, then import the file back by ID with media import on.

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