After Moving a Site to Another Domain, All Images Are Lost

It sounds like you need to change the URLs for the old images. The easiest & quickest way of doing that is to do a find and replace on the MySQL database.

You can use PHPMyAdmin (usually provided by your web host) or other MySQL editing software such as Sequel Pro to make changes to your MySQL database without touching the WordPress admin area. This means you can make wide-scale changes by running SQL queries instead of making them one-by-one, which is tedious and time-consuming.

Remember to take a backup of your database first. To do this in PHPMyAdmin, select your database from the sidebar on the left, then click “Export”. The “Simple” method is fine, but if you want more control over it then the “Custom” method gives you plenty of options.

After taking your backup, click on the SQL tab and paste the following into the textarea:

UPDATE wp_options SET option_value = replace(option_value, 'oldurl', 'newurl') WHERE option_name="home" OR option_name="siteurl";

UPDATE wp_posts SET guid = replace(guid, 'oldurl','newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'oldurl', 'newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'oldurl','newurl');

And replace “oldurl” with your old URL and “newurl” with your new URL, keeping the http:// but removing trailing slashes. Double check it, then when you’re happy with it, click the Go button.

Navigate over to your site and check whether your images are working. If not, it’s usually because of a typo, which you can fix by restoring the database from the backup you made at the beginning of the process and trying again.

There’s a expanded guide to WordPress domain migration at this site, which also has a link to a script to generate the SQL query for you.

Leave a Comment