WordPress Logo

How to Change WordPress Site Address (URL)

You are here:
Estimated reading time: 4 min

You need to know how to change your WordPress site URL whether you are updating your site to use HTTPS, changing your domain name, migrating from a local server to a live site, or transferring to a subdomain.

We will provide you with a step-by-step procedure on how to change your WordPress site. Make sure to generate a full backup of your website before making any changes.

Steps on How to change your WordPress site URLs

Change the WordPress URL in your WordPress Admin Dashboard

Adjusting your WordPress URL in the admin dashboard may be all you need to change a domain name, however, some sites may have the URL hardcoded in the wp-config.php file in these cases, you will have to use method 2 below.

  • Log into your WordPress admin dashboard
  • Click on Settings → General.
  • Update WordPress Address (URL) line and Site Address (URL) lines with your new domain name. Both of these fields(Site Address and WordPress Address URL) should be the same.
  • Save changes
  • Visit your website to make sure everything is working as it should.

Using wp-config.php File

You need to access the wp-config.php file first, this file is located in the root folder of your
website.
To change this file you need to connect to your website using an FTP client (OR cPanel > File Manager).

  • Locate the wp-config.php file, which can be found in the root folder for your domain.
  • You need to add the code below just above the line that says ‘That’s all, stop editing! Happy publishing.

define( ‘WP_HOME’, ‘https://examplesite.com‘ );
define( ‘WP_SITEURL’, ‘https://examplesite.com‘ );

  • You will need to replace ‘https://examplesite.com’ with your new domain name.
  • Save changes and upload the file back to your server (Only when using FTP).
    Visit your website to make sure that everything is working fine.

Using functions.php File

For some reason, if you are unable to access your WordPress admin panel, then you will need to use this method.

  • Using an FTP client, you can connect to your WordPress site
  • Locate your WordPress theme folder. For most users, this will be something like /wp-content/themes/your-theme-folder/.
  • Locate functions.php file via FTP (or cPanel > File Manager)
  • using your preferred text editor like Notepad, open your functions.php file and edit it
  • Add the code below to the bottom of the file.

update_option( ‘siteurl’, ‘https://examplesite.com‘ );
update_option( ‘home’, ‘https://examplesite.com‘ );
Replace ‘https://examplesite.com’ with your own site URLs.

  • Save changes and upload the file back to your server using FTP.
    Visit your website to make sure everything is working as it should.

This method updates the site URLs in the database. You need to remove the two lines of code from your WordPress functions.php file once your website is working properly.

Using SSH

  • Enable SSH access in your cPanel using this guide.
  • Log into your cPanel > Advanced > Terminal:
  • Find your website directory using the command below:

cd rootdirectory

  • Where the root directory is the main folder of your installation (e.g., public_html for the main domain).
  • Run the command below:

wp search-replace ‘http://oldsite.com‘ ‘http://newsite.com

The links in your database will be changed to the new domain name.

Using phpMyAdmin

In case you do not have access to the WordPress admin dashboard or Terminal, follow these steps to change the URLs via the database.

You can update WordPress site URLs by changing them directly in your WordPress database. This can be done from within your hosting account dashboard using phpMYAdmin. Your site could break if the changes made to your database are not done properly. So, it is recommended to take a WordPress database backup or check with a developer. This is really important and will help you undo any WordPress database changes if anything goes wrong.

  • Log into your cPanel
  • Locate the database associated with your website in wp-config.php file
  • Click phpMyAdmin in the ‘Databases’ section.
  • Click on the database in the left-side column and wp-options(by default wp_ is the database prefix but it can be different for your installation)
  • You will see rows inside the options table. You need to locate the ‘option_name’ column where ‘siteurl’ and ‘home’ will be listed.
  • Click on the pencil ‘Edit’ icon to the left of each row and change the ‘option_value’ field to your new site URL.
  • Click the ‘Go’ button in the bottom right corner to save your database changes.

Visit your website to make sure everything is working as it should.

Some references in the database may not be reassigned to the new domain, in this case, you have to update all links following the steps below.

  • Locate the database associated with your website in wp-config.php file
  • Right-click on wp-config.php > View or Edit option:
  • Download the backup of the database. You can take a backup from within your cPanel > Files section > Backup menu
  • Open .sql file with some text editor and update all URL references
  • Using Ctrl + F and select Replace option.
  • Fill in the corresponding fields
  • Replace your old domain with your new domain and click Replace All:
  • Save changes.

Create a new database in your cPanel account

  • Upload the updated database using the phpMyAdmin menu in the Databases section
  • Select the newly created database from the list on the left and use the switch to Import tab. Import the database .sql file from your local device
  • Once done, you will need to update the wp-config.php file in your installation root folder:

These are the fields to be changed
define ‘DB_NAME’ line – the name of the new database you’ve created in MySQL Databases menu.
define ‘DB_USER’ line – the name of the new user you you’ve created in MySQL Databases menu.
define ‘DB_PASSWORD’ line – the new password you’ve set for database user in MySQL Databases menu.

  • Save changes.
  • Delete the old database once you confirm that everything is working fine
  • Proceed to your WordPress admin page to re-generate the permalinks to make sure they have the new URL.
  • Log into your WordPress dashboard in the Settings menu > Permalinks.
  • If you had a Post name, switch it to Plain
  • Save changes and then revert everything back

Using WP-CLI

This option uses the WordPress Command Line Interface (WP-CLI) to access and edit your site. The process involves using command lines to run specific tasks as such you need the help of a developer.

The commands to edit your URL are as follows:
wp option update home ‘http://examplesite.com
wp option update siteurl ‘http://examplesite.com
Replace “examplesite” text with your existing domain to get this done!

You have a number of methods to choose from to change your WordPress URL

You can change the settings in the WordPress admin, hardcode them in your wp-config.php file, edit the database, use WP-CLI or use a plugin.

Work through the methods above to find the one that suits your site, and you’ll have your new WordPress URL working in no time.

Was this article helpful?
Dislike 0

Author

Joshua

Web Hosting Geek Technical Support Staff G Online Sites