BlogChange domain name in WordPress

31st July 2013

Due to a large number of hard-coded references to the domain on which a site is hosted it can be a pain to change domain name in WordPress. This causes a problem when moving sites from one domain to another.

There are a couple of quick fixes for this (available here). However, I've found these less than helpful as they tend to mask the problem and relieve you of some control. If you have access to the MySQL behind your site then it is better to just go in and change all instances of the domain name to the new domain.

Here's a handy tidbit of SQL which I use whilst moving Wordpress sites from one domain to another. It literally just finds and replaces all references to the old domain with the new domain name...

set @old = 'olddomain.co.uk';
set @new = 'newdomain.co.uk';

UPDATE wp_options
SET option_value = replace(option_value, @old, @new);

UPDATE wp_posts
SET guid = replace(guid, @old, @new);

UPDATE wp_posts
SET post_content = replace(post_content, @old, @new);

UPDATE wp_postmeta
SET meta_value = replace(meta_value, @old, @new);

Let's Talk