Summary

Learn how to quickly change image URLs in WordPress. Useful if you’ve recently changed your WordPress domain name and your images are no longer showing.

By default, WordPress saves links to images at the time your post or page was published. You can use the following SQL Query to update your posts to use the new URL.

We provide examples for WordPress and WordPress Multisite (formerly WordPress MU).

Make sure you have backup your WordPress database before running any SQL queries.

Examples

Update image urls in WordPress – Single site


UPDATE wp_posts SET post_content = replace(post_content, 'http://www.your-old-domain-name.co.uk', 'http://www.your-new-domain-name.co.uk');
UPDATE wp_posts SET guid = replace(guid, 'http://www.your-old-domain-name.co.uk', 'http://www.your-new-domain-name.co.uk');

Update image urls in WordPress – Multisite (Formerly WordPress MU)

Remember to replace 100 with the ID number of your blog.


UPDATE wp_100_posts SET post_content = replace(post_content, 'http://www.your-old-domain-name.co.uk', 'http://www.your-new-domain-name.co.uk');
UPDATE wp_100_posts SET guid = replace(guid, 'http://www.your-old-domain-name.co.uk', 'http://www.your-new-domain-name.co.uk');

You’ll need someway of running the above SQL queries against your WordPress database.

We recommend phpMyAdmin or installing a WordPress database like WP-DBManager which offers built-in support for SQL queries.