How to Change the Domain Name of a WordPress Site

How To Change The Domain Name Of A WordPress Site

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:

define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' );

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 “”

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:

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.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Larry Alton Avatar

Read next

Suzanne Simard sealed paper birch and Douglas fir seedlings inside plastic bags, fed them carbon-14 and carbon-13 dioxide, and nine days later found carbon had crossed between species through fungal threads in the British Columbia soil beneath her boots
A species of jellyfish called Turritopsis dohrnii can revert its adult cells back to a juvenile polyp stage when injured or starving, effectively restarting its life cycle, and biologists have so far failed to identify any natural limit to how many times it can do this.
A Japanese man named Jiroemon Kimura, who lived to 116, was born in 1897 when Queen Victoria still ruled and died in 2013, meaning a single human life personally overlapped with the invention of the airplane, the atomic bomb, the internet, and Instagram
The Hollywood sign originally read HOLLYWOODLAND when it was built in 1923 as a real estate advertisement for a housing development, and it was only meant to stand for 18 months, but nobody ever got around to taking it down and the city eventually adopted it as a landmark
Almost all of the world’s internet traffic does not travel by satellite but through fibre-optic cables lying on the ocean floor, a hidden web of wires crossing the deepest parts of the sea to connect the continents.
People who flip their phone face down on every table aren’t being secretive. They figured out that staying interruptible meant handing their time to whoever rang first
Twitch vs. Facebook Gaming vs. YouTube Gaming: What’s the Best Live Game Streaming Platform?
Chrome Extensions Ownership Transfer is a Direct Threat to You: How to Stay Safe