Changing a Domain Name with a WordPress Installation

Recently a company I did some contract work for decided to change the domain name associated with their website hosting.  As a result, their website, which was built on WordPress, no longer functioned correctly.  While the posts and other information were being pulled in, all the formatting was gone.

The reason for this is that WordPress is database centered.  All the information about your site is saved in that database, including your URL.  That URL is used to make the links to the templates and downloads.  If you change your domain name, you’ve changed your URL.  If you change the URL without changing the database, your site is not going to look correct.

Ideally, just  before you make the change you should log into your site,  click on Settings->General and then change the URLs here:

  • The “Home” setting is the address you want people to type in their browser to reach your WordPress blog.
  • The “Site URL” setting is the address where your WordPress core files reside.

Note: Both settings should include the http:// part and should not have a slash “/” at the end.

What should you do if you’ve already change the domain name and find yourself locked out?

If you have access to the site via FTP, then this method will help you quickly get a site back up and running, if you changed those values incorrectly.

1. FTP to the site, and get a copy of the active theme’s functions.php file. You’re going to edit it in a simple text editor (like notepad) and upload it back to the site.

2. Add these two lines to the file, immediately after the initial “<?php” line.

update_option('siteurl','http://example.com/blog');
update_option('home','http://example.com/blog');

Use your own URL instead of example.com, obviously.

3. Upload the file back to your site, in the same location. FileZilla offers a handy “edit file” function to do all of the above rapidly; if you can use that, do so.

4. Load the login or admin page a couple of times. The site should come back up.

5. Repeat the above steps, but remove those lines. IMPORTANT: Do NOT leave those lines in there. Remove them immediately after the site is up and running again.

If there is no functions.php file in the theme:

Create a new text file called “functions.php”.

Edit it with notepad, and add this text to it, using your own URL instead of example.com:

<?php
update_option('siteurl','http://example.com/blog');
update_option('home','http://example.com/blog');
?>

Upload that to your theme directory, then proceed as stated above. Remove the file afterwards.

~WordPress.org

Note: Another problem I’ve run into with former clients is changing hosting.  In one case, the new webmaster simply copied all of the files over and terminated the previous hosting.  The database was not transferred over and three  years of daily posts were completely lost.  If you want to change hosts and you have a WordPress installation, please contact me before you do anything!

Follow me

Submit a Comment