Changing WordPress site URL will be required in your work with WordPress from time to time.

 

These are only some of the cases that you may need to change your site WordPress Site URL:

  • Changing business name which requires change in domain name
  • Moving from a subdomain installation to an installation in the main domain e.g. blog.example.com => example.com
  • Moving from a staging site to live site (client-name.example.com => client-name.com
  • and many more

Here are the ways that you can go about changing the URL

1. From WP Admin > General Settings

  • WordPress Address (URL)
  • Site Address (URL)

7 Ways to Change WordPress Site URL WP Admin > General Settings

 

2. Define these constants into your wp-config.php file.

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

3. Using update_option in your functions.php (one time only)

Add these lines to your functions.php file of your current theme (after the starting <?php tag):

[code]
update_option( 'home', 'http://example.com' );
update_option( 'siteurl', 'http://example.com' );
[/code]

Visit your site so the WordPress options are update.
Then remove those lines because it will add unnecessary load to your WordPress site.

4. Using wp-cli to update the site url

If you have ssh access to the server you can use the following command line commands to update the site url using WP-CLI

[code]
wp option update home 'http://example.com'
wp option update siteurl 'http://example.com'
[/code]

5. Define RELOCATE constant in the wp-config.php and let WordPress determine the new Site URL.

[code]define( 'RELOCATE', true );[/code]

Then remove the line because it will add unnecessary load to your WordPress site.

6. Using mysql command line or from phpMyAdmin

[code]
UPDATE wp_options SET option_value = 'http://example.com' WHERE option_name = 'home';
UPDATE wp_options SET option_value = 'http://example.com' WHERE option_name = 'siteurl';
[/code]

7. Ask for help

If you can ask your hosting provider or fellow developer to make the change for you.

Note: Keep in mind if your site was running under a different address and the content contains links pointing to its pages the site most likely contains links pointing to the previous Site URL. You will need to use a search and replace tool to update the content so old links point to the new address correctly.

Related

Referral Note: When you purchase through an referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer