Changing Domain Name With WordPress

Simple one this but I always have to look up the code so thought I’d write it somewhere I can find it at ease.

If you move a site to a new domain and are using WordPress your CMS, after restoring your database you will need to run the below script to change the references in the database to the new domain you are configuring the site for.


SET @newURL = 'http://hitchinsit.co.uk';
SET @oldURL = 'http://new.hitchinsit.co.uk';

SELECT @newUrl;
SELECT @oldUrl;

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);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s