At some point you may discover the need to change the domain name of your WordPress website. Maybe you found a better domain name, or you were using a temporary domain to set everything up. Either way you’ll need to change a few settings inside of your WordPress installation in order to make the transition to your new domain smooth.
If you need to migrate your website to a new server, please refer to this guide for migrating without experiencing downtime.
Prepare by gathering all necessary information
Before you change your domain name, you’ll need the following information immediately accessible:
- Your WordPress administrator login credentials. This is the username and password used to log in to the WordPress dashboard.
- Your file manager or cPanel login credentials.
- Your FTP login credentials.
- Access to PHPmyAdmin through your control panel.
You’ll also want to make a complete backup of your WordPress installation.
Here are four options for changing your WordPress domain name, starting with the easiest method and ending with two options that should only be used if you can’t get the first two to work.
1. Change the domain name through the WordPress admin panel
The easiest way to change your domain name is to log in to your WordPress admin account and navigate to the General Settings page. You’ll see two options called “WordPress Address (URL)” and “Site Address (URL).”
Change these two URLs to your target domain name. In most cases these two URLs will be the same, but they’ll be different if you’re storing your WordPress files in a different directory than the domain used to access the site. If this is the case, make sure you edit the “WordPress Address” option to reflect the directory where your WordPress files are. The “Site Address” URL is the address you want people to type in to access your website.
This option will work if you have no problem accessing your admin dashboard. If you can’t access your admin dashboard, the next option will help.
2. Edit the database through phpMyAdmin
Before making any changes to your database, be sure to back it up in cPanel or whatever control panel you’re using.
Navigate to phpMyAdmin and find your WordPress database listed in the column on the left. Click on the database name to select it. You’ll see a list of tables appear below the database name. Find the table called “wp_options” and click on it. There are two rows inside of this table that you need to edit: “siteurl” and “home.” These should appear as the first two options. Edit these values to reflect your target domain, and you’re done!
3. Edit the wp-config.php file
If the first two options don’t work, you can edit the “wp-config.php” file directly. You can edit this file inside of your file manager, or you can download the file to edit and upload through your FTP client.
You want to identify the two lines of code that define your domain name URLs. They’ll look like this:
Replace both instances of “example.com” with your target domain name.
This option for changing your domain name will work but should be used as a last resort. When you edit your “wp-config.php” file manually, you are essentially hard coding the site values into your website and will no longer be able to edit those values from within your general settings in the admin dashboard.
4. Edit the functions.php file to update the database
This option is a temporary command and should not be used as a permanent solution. Use this method only when all other options have failed and/or your site is not accessible through the front end.
Add the following two lines of code directly after the “”<?php” line in functions.php and be sure to replace both instances of “example.com” with your target domain:
update_option( 'siteurl', 'http://example.com' ); update_option( 'home', 'http://example.com' );
Upload the edited file to your site, and then log in to the admin page a few times. This will trigger an update of your options in the database. Once your site is functional, you should remove the two lines of code from the functions.php file. The database will remain updated.
If your WordPress theme doesn’t have a functions.php file, you can create one by wrapping the two lines of code listed above in php tags like the following:
<?php update_option( 'siteurl', 'http://example.com' ); update_option( 'home', 'http://example.com' ); ?>
The above code can be saved in a plain text file called “functions.php” and uploaded to your theme’s main directory. You’ll want to log in to your admin panel a few times to trigger the command, and then remember to delete this file after your database has updated the options.
After changing the proper values using one of the options above, the domain for your WordPress website should now be changed.