Changing a WordPress site’s domain name

September 10th, 2012

About the Author: Dan

I’m Dan Smart, a 38 year old website developer, based in Swansea, UK. I have worked in the software development industry for over 15 years, with experience in web development, mobile handset development, and mobile networks. I work both on websites and web applications with systems such as Wordpress, Laravel, Backbone, Angular.js, node.js and mobile app development with PhoneGap, iOS, and Android. When I’m not developing websites and software, I am a keen runner, involved with mime performance group Innovo Physical Theatre, and also actively involved in my local church.

* Follow me on Twitter or contact me

If you want to change a WordPress site’s domain name (or base URL), which will often happen when you’re copying a site from staging to production, or from local to live, there are a number of steps to following, outlined at

However, here is a shortened summary of how I run this on non-multisite sites (multisite sites are a pain!):

1. Copy the files to the new server (or folder on your local machine, if you’re making a local copy of a site)

2. Set up your database and permissions, and fill in the details in wp-config.php

3. Set up your domain name to point to the correct server (e.g. edit your vhosts file, if it’s a local copy).

4. Before trying to access wp-admin, you’ll need to change the site_url option. The simplest way I’ve found comes from the Moving_WordPress page:

a) Open up wp-login.php

b) Find this line:

require( dirname(__FILE__) . '/wp-load.php' );

and insert the following lines below:

//FIXME: do comment/remove these hack lines. (once the database is updated)
update_option('siteurl', '' );
update_option('home', '' );

c) Go to (rather than directly to and log in. This will update the options for you.

d) Remove the lines you added to wp-login.php

5. Now you should be able to have access to the WordPress admin dashboard, however you now need to update all the URLs that refer to the old domain name.

6. Download and install the great Search and Replace plugin.

7. Go to Tools -> Search and Replace, and do a search and replace (in the bottom section first) in all the tables it lists, of your old domain to your new domain name (don’t put the http:// bit on, makes sure it covers all). This will do a safe replace of all serialized WordPress data.

You should be ready to go. Occasionally you have to use the ‘drastic’ search and ‘replace all’ (at the top of the Search and Replace page) to pick up a few instances in tables that aren’t covered by the plugin, but this is less often.

Do you have a better way? Let me know in the comments below.

Switch to mobile version