Moving WordPress sites to a new domain

When developing new WordPress websites we often host the site on a temporary domain. When we are ready to go live we then switch to the live domain. However, a problem occurs with this approach as WordPress remembers the domain it was installed on, and is very reluctant to move.

All of the site links, img src tags, stylesheets and essentially every other object used in the site build, will be directly pathed to (will still point at) the old domain.

The simple answer is to either manually change these settings within the interface and reupload the images. This is very inefficient and not necesary, these URLs can be amended directly within the WordPress database. Correcting these errors manually, however, can be time consuming.

This is the bit where we tell you that we have a faster solution. You simply need to run these four queries against your WordPress database. Remember to replace “olddomain.com” and “newdomain.com” with your existing and new domains.

UPDATE wp_posts SET post_content =
REPLACE(post_content,'www.olddomain.com','www.newdomain.com');

UPDATE wp_posts SET guid =
REPLACE(guid,'www.olddomain.com','www.newdomain.com');

UPDATE wp_postmeta SET meta_value =
REPLACE(meta_value,'www.olddomain.com','www.newdomain.com');

UPDATE wp_options SET option_value =
REPLACE(option_value,'www.olddomain.com','www.newdomain.com');
Posted in Tips and tricks, WordPress news |

Leave a Reply