Web server stores the site’s content and you can use the site address from the clients like browser to access the site. Though servers store the address as IP, you can use the descriptive address to map using domain resolution. In many situations, you have to change the descriptive site address by keeping the same content. Content management systems like WordPress allow you to change the site address easily. In this article, we will explain different methods to change site address in WordPress.
Table of Contents
Reasons for Changing Site Address
Here are some of the reasons you may need to change the site URL:
- Migrating from one domain to another domain
- Moving site from temporary domain provided by your hosting company your own domain
- Moving local installation to live server
- Change the location of WordPress installation
Site URL Vs WordPress URL
Before we proceed, you have to understand two terms with respect to URL. WordPress offers the below two terms:
|Admin Panel Name||DB Field Name||Config Parameter||Purpose|
|WordPress Address (URL)||siteurl||WP_SITEURL||Location of your WordPress installation|
|Site Address (URL)||home||WP_HOME||Address of your website’s home page|
In general, these two URLs are same when you have your WordPress installation on the root of your domain. However, you can install WordPress in a separate subdirectory while keeping the public website address as a root domain name. similarly, you can also install WordPress on a root domain but use subdirectory as a site address.
Methods to Change Site Address in WordPress
- From admin panel settings
- Using config.php file
- Adding entries in functions.php file
- By editing database
Let us explain each topic in detail.
Change Site Address from Admin Panel
This is the most easy and convenient way of changing WordPress address URL or site address URL. Login to your WordPress admin panel and navigate to “Settings > General” section.
You can change the site address by providing the detail here. After changing the site address, you can scroll down and click on the “Save Changes” button. For example, you can change the address to add “/123” as suffix. This will change all the URLs on your site from “yoursitename.com/” to “yoursitename.com/123/”.
Remember, your WordPress address URL should be the location where installation files are available. Therefore, you should not change this unless you have installation available on the new location. If you change this wrongly, you will be instantly logged out of the admin panel.
You website may not work completely or show jumbled content in unreadable manner. You can change the WordPress address only in situations like changing domain name or moving the installation to other location.
Using Config.php File
If you made a mistake from admin panel, you will be logged out and the login page will show you 404 page not found error. In any troubleshooting situation without access to admin panel, you can follow this option to add entries in wp-config.php file.
- Use File Manager app in hosting account or use FTP client to login to your web server.
- Locate wp-config.php file on the root of your installation and edit the file.
- Add the following entries and save/upload the file back to server.
define( 'WP_HOME', 'http://localhost/123' ); define( 'WP_SITEURL', 'http://localhost' );
Now you can login to your admin panel and check the site address by navigating to “Settings > General” section. As you can see below, the addresses will be frozen and you will not be able to edit them like below.
Go back to your wp-config.php and delete the entries you have added. This will change the WordPress address and site address URL same and editable from admin panel. You can modify the correct site address and save your changes. Since wp-config.php entries will not overwrite database entries, you can use this method only for troubleshooting purpose to login back to admin panel.
Note: As given in the above table, home URL is the one you should edit for changing site address in WordPress. The siteurl is actually the WordPress address of your installation path. This is a confusing fact that the frontend and backend names are different.
Using functions.php File
Similar to wp-config.php file, you can also use functions.php file to restore access to your WordPress admin panel. You can find functions.php file using File Manager app or with FTP under “/wp-content/theme/your-theme/” folder. Simply add the following lines in your functions.php file and save.
update_option( 'siteurl', 'http://localhost' ); update_option( 'home', 'http://localhost/123' );
Now, login to your WordPress admin panel to see the site address is updated.
There are few differences between using functions.php compared to wp-config.php method:
- You can edit the addresses from the admin panel with functions.php option
- The changes are updated in the WordPress database
- File functions.php is part of your theme. Hence, any theme update or theme change will disable the changes.
Editing Database Entries
WordPress stores the addresses in wp_options table in the database. You can modify the entries to change site address.
- Log into your hosting account and open phpMyAdmin tool.
- Locate your database and click on “wp_options” table.
- The first entry is with the “option_name” as “siteurl” which is the WordPress address URL.
- By default, the tables in database will show 25 entries. Click on the next arrow button to go to the next page.
- On the next page, you can see the “option_name” as “home”.
- Double click on the “option_value” filed to edit the site address and change as per your need.
- Simply click outside to save your changes.
- Go back to admin panel and check the site address is changed.
WordPress SEO: Optimize WordPress site with free WordPress SEO guide.
Caution in Changing Site Address
Unless you know what you are doing, we do not recommend you to change the site address and play around.
- Changing the site address will completely change the URL of all the pages on your site. Make sure to setup 301 redirects to retain your search engine rankings.
- Wrongly changing WordPress address will log you out from admin panel instantly. You have to use one of the above explained methods to regain the access to admin panel.
- You need to enter http or https and in the site address URL.
- Make sure to provide correct URL with or without www.
- You should not include the back slash / in the address.
Many hosting companies allows you choose http / https and www / non-www options during installation. You should type the correct option chosen with the installation and in the site address field in WordPress admin panel. Otherwise, you will face infinite redirect loop when trying to access the site and admin panel.
For example, you might have installed the site on “https://www.yoursite.com” but wrongly provided the site address as “https://yoursite.com” without www. In this case, when you try to access the site on a browser, it will cause redirect loop between www and non-www versions. Your server will force the address with www and WordPress will force to remove www. You can see this in browser’s status bar that the site address is going in the loop. Therefore, make sure to type the correct site address to avoid such problems.