WordPress: Globally update URL

In WordPress, instead of using relative URL when referring to posts, pages and images used within the site, absolute url is used.

This becomes a problem if your development site and production sites are different. All links and images in contents are still referencing the development site even though the site has moved to production.

This problem is also applicable if you’re changing domain name of your site.

Besides changing URL, you need to globally change all references to development / staging URL to production URL in all contents.

There are plugins that can do the work for you. However it’s quicker if you have access to MySQL.

Simply run the sql:

update wp_posts 
set post_content = replace(post_content, 'from-old-url.com', 'to-new-url.com');

Leave a Reply

Your email address will not be published. Required fields are marked *