Different Ways To Change The WordPress “home” And “siteurl” Links

Apr 05, 2019
Different Ways To Change The WordPress “home” And “siteurl” Links

Every once in a while, you may need to manually change (or fix) your WordPress siteurl and home links. A common scenario when this is necessary is when you’re migrating your entire website to a new domain. If not done right, your site may stop functioning properly and you may even inadvertently lock yourself out.

This article will discuss the different proper methods of changing these settings. But before we go into the details, let’s understand what the siteurl and home links are.


On the General Settings page of your WordPress website, you will find both links defined. Like this:

"Different Ways To Change The WordPress siteurl And home Links"

The fields of interest are:

  • the WordPress Address (URL) (also referred as siteurl or WP_SITEURL) and
  • the Site Address (URL) (also known as home or WP_HOME)

The “siteurl” Or “WP_SITEURL” Or “WordPress Address (URL)” Link

Your siteurl is the address where your WordPress core files reside. As a way of keeping things organized, some web admins like to put website files in a sub-folder of root instead of directly on the root folder. But in most cases, people just leave everything on root. This is why most times, both the siteurl and home links will be the same.

The “home” Or “WP_HOME” Or “Site Address (URL)” Link

The home link is the link that you want your site visitors to type in a browser when they want to access your site.

So, for example, you may put all of your website files inside of a folder named fileslocated in your root folder (like this https://masterjosh.site/files/). However, when users want to visit your website, you probably don’t want them to have to enter the /files/ path every time. It makes more sense for them to just type the site root directly into the browser (like this https://masterjosh.site/).

In the this case, your siteurl would be https://masterjosh.site/files/, whereas https://masterjosh.site/ would be your home link.

Changing The WordPress “siteurl” And “home” Links

Now that we’ve differentiated between the WordPress siteurl and home links, let us take a look at four different ways of changing these links.


The four methods are:

  1. The wp-config.php method
  2. The functions.php method
  3. The RELOCATE method and
  4. The direct database method

Let’s now discuss/demonstrate each method. I will be using my website’s address https://masterjosh.site in the examples. Make sure you change this to the values you want.

1. The wp-config.php Method

This one is a pretty simple method. Just add the snippet below to your wp-config.phpfile and save it.

define('WP_HOME', 'https://masterjosh.site');
define('WP_SITEURL', 'https://masterjosh.site');

By doing this, you’re actually hard-coding the values into WordPress. The downside to this method is that you will no longer be able to edit the values in the General Settings section of your WordPress dashboard.

2. The functions.php Method

Add these two lines in your theme’s functions.php file. Put them right after the initial <?php line.

update_option('siteurl', 'https://masterjosh.site');
update_option('home', 'https://masterjosh.site');

Load the WordPress admin or login pages a couple of times. The values will get updated and your site should come back up.

An important thing to note when using the functions.php method is that you should NOT leave the above two lines of code inside the functions.php file. If you do, the values will keep getting updated on every page load, by every user on your website. That is not a good thing. Once the lines of code have done their job, delete them and save your functions.php file again.

If you later need to change the values again, as long as your website is still up and running, you can just change them from the General Settings admin page.

3. The RELOCATE Method

If you need to migrate your website to a new domain name, WordPress has an automatic relocation feature to help you get this done quickly. By default, your wp-login.php file contains this piece of code which only gets triggered if you have set RELOCATE to true in your wp-config.php file.

( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set
    if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
        $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], "", $_SERVER['PHP_SELF'] );
    $url = dirname( set_url_scheme( 'http://' .  $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
    if ( $url != get_option( 'siteurl' ) )
        update_option( 'siteurl', $url );

Don’t copy the above code. You don’t need to put it anywhere. It already exists inside your wp-login.php file.


To use the RELOCATE method, edit your wp-config.php file. After all your existing define statements, just before the end of the file, insert this line of code:

define('RELOCATE', true);

Open a browser and manually point it to your wp-login.php file on the new domain name. So, if your new website address is https://new.masterjosh.site, then type https://new.masterjosh.site/wp-login.php into the address bar.

Login as usual.

Confirm that you’re indeed logged in to the new site. If you logged in to the new site successfully, go to your General Settings admin page and verify that both the address settings are correct.

If all is good, go back to your wp-config.php file and remove the RELOCATE definition line you previously added. This is important for security reasons.


The “magic” that happened using the RELOCATE technique above is actually quite simple. When the RELOCATE flag is set to true, the siteurl will be automatically updated to whatever path you are using to access the login screen. This will get the admin section up and running on the new URL, but it will not correct any other part of the setup. You will still need to alter the rest manually.

4. The Direct Database Method

Before using this method, be sure to back up your database and save a copy of it off your server.

The idea behind the direct database method is to change the siteurl and home links directly in the wp_options table of your database (assuming your WordPress table prefix is wp_).

Using the MySQL command line (if you have root access on your server), or phpMyAdmin, or HeidiSQL, or whatever other tool you use for working with your database, run the following queries on the database powering your WordPress site.

SELECT * FROM wp_options WHERE option_name = 'home';
UPDATE wp_options SET option_value="https://masterjosh.site" WHERE option_name = "home";
SELECT * FROM wp_options WHERE option_name = 'siteurl';
UPDATE wp_options SET option_value="https://masterjosh.site" WHERE option_name = "siteurl";

Again, the code snippet given above is based on the assumption that your table prefix is wp_. So, be sure to enter your real table prefix when using this code. You should be able to access your site again once your database is updated.

Add Comment