How to Change Your WordPress URL
There is a multitude of reasons why you might need to change WordPress URLs occasionally. However, it is not always clear when and how you can do it. This is why we decided to shine some light on the topic.
We use the term WordPress URLs to refer to two addresses – the WordPress address and the site address. In most cases, the WordPress and the site address should be the same. The WordPress address represents the location of core WordPress files. So, when you use this address (i.e. the your-wordpress-url/wp-admin URL) you log in to your admin dashboard. If the location of your WordPress core files changes (e.g. when creating a subdirectory), your WordPress address also needs to change to keep everything working normally.
On the other hand, your site address is the address your visitors type into their browser to access the website (i.e. its frontend). Most of the time, both the WordPress and site address are the same. However, now that you know what each address represents, you won’t be confused if you find that the addresses differ. Let’s take a look at the cases in which you can change your WordPress URLs and how you should do it. To help you navigate, we’ve broken this article down into the following topics:
When to Change WordPress URL
There are various circumstances that might require you to change your WordPress URLs. For example, switching your site from HTTP to HTTPS. It’s a must if you’re changing domains or creating subdirectories or migrating your site from a local server. Also, changing WordPress URLs is a valid troubleshooting step as well, especially if you’re facing redirect errors. Alternatively, you can change your URLs to make them more SEO friendly. Whatever your reason may be, knowing how to change WordPress URLs will be useful on many different occasions.
How to Change WordPress URLs
There are several ways to change WordPress URLs. We are going to explain the most common ones, going from least to most challenging methods. However, applying some of them will require you to edit important WordPress files or even the database itself, so it is essential that you backup your site in advance. Once you’ve done that, you can proceed to change your URLs using one of the methods described below.
If you can log in to your dashboard and have the permissions to change both the WordPress and site address, this is the method we recommend.
Log in to your dashboard using your admin credentials and navigate to Settings > General. Now you only need to update the WordPress Address (URL) and the Site Address (URL) fields by typing the new addresses for each of them. To finish, simply press the Save Changes button in the corner of your screen.
Afterward, revisit your site to check that no issues have appeared.
However, in case you can’t log in to your admin dashboard, you will have to try one of the more technical approaches to updating WordPress URLs. The same applies if you log in but the WordPress Address and Site Address fields are grayed out so you can’t edit them.
You should try this method if you can’t access the WordPress admin dashboard or if you are experiencing a login redirection issue. Also, if the fields for WordPress Address and Site Address are grayed out this can mean that the URLs are already hardcoded inside your wp-config.php file. Please note that this method requires you to work from within the wp-config.php file so you should have some basic technical knowledge or follow the instructions below carefully. You can edit the wp-config.php file either via FTP or using a control panel such as cPanel.
-
Via FTP
To edit the wp-config.php file, connect to your server using your FTP credentials and navigate to your root WordPress directory. Locate the wp-config.php file, right-click it and select the View/Edit option from the dropdown menu.
Open the file using a text editor, find the line containing /* That’s all, stop editing! Happy blogging. */ and insert this code above it:
define('WP_HOME','https://your-website.com'); define('WP_SITEURL','https://your-website.com');
Depending on the text editor you’re using, the result should look something like this:
Don’t forget to replace the your-website part with your actual website URL. If your URL contains www, don’t forget to add that as well.
Afterward, save the changes and upload the edited file back to your server, overriding the current file.
-
Via cPanel
Connect to cPanel using your credentials and click on the File Manager option located near the top.
Navigate to your root WordPress directory (often called public_html) and locate the wp-config.php file within it. Right-click it and select the Edit option from the dropdown menu.
The file will be opened in a new tab, using your default editor. As with FTP, find the /* That’s all, stop editing! Happy blogging. */ line and insert this code above it:
define('WP_HOME','https://your-website.com'); define('WP_SITEURL','https://your-website.com');
Make sure to replace the your-website part with your actual website URL. Also, make sure to add www, if your site URL contains it.
The result should look something like this:
To finish, press the Save Changes button.
Afterward, make sure to revisit your site’s frontend to check that everything is working properly.
This method is convenient when you are unable to log in to your admin dashboard. You can edit the WordPress URLs through the functions.php file of your theme. As an added benefit, once you’ve inserted the code into your functions.php file, the URLs will automatically be changed in the database. We will show you how to edit the file using either an FTP or the cPanel.
-
Via FTP
Connect to your server using your FTP credentials and locate the root WordPress directory. Navigate to /wp-content/themes and click on your theme’s directory (twentytwenty, in our case) to open it.
Find the functions.php file, right-click on it and select the View/Edit option from the dropdown menu.
Open the file using a text editor and insert this code at the bottom:
update_option( 'siteurl', 'https://your-website.com' ); update_option( 'home', 'https://your-website.com' );
Replace the your-website part with your actual website URL. If your site has a www, make sure to add it as well.
-
Via cPanel
Log in to cPanel using your credentials, navigate to the Files section near the top and click on the File Manager option.
Then locate your root WordPress directory (public_html) and navigate to /wp-content/themes/ afterward. Click on the directory of your theme (twentytwenty, in our case) and locate the functions.php file within the directory. Right-click on the file and select the Edit option from the dropdown menu.
The file will open in your default editor. Add the following code at the end of the file.
update_option( 'siteurl', 'https://your-website.com' ); update_option( 'home', 'https://your-website.com' );
Make sure to replace the your-website part with your actual website URL. If your site has a www, add it as well.
Afterward, click on the Save Changes button.
Then visit your site once more to see if everything is working. If it is, you can simply remove the two previously inserted lines of code as they’ve done their job.
The final method we are going to show you is changing WordPress URLs directly inside your database. Please note that this might break your site if done incorrectly. If you don’t feel comfortable with doing this on your own, seek help from a developer.
Now, let’s take a look at the way you can change the WordPress URLs in your database. First, you should be logged in to cPanel. Next, find the Databases section near the top and click on the phpMyAdmin option.
A new page will open. Locate your database from the list on the left and click on it. Find the options table within and click on it. Keep in mind that the default prefix for WordPress databases is wp_ so the table you’re looking for will be listed as wp_options. However, if you’ve set a custom prefix for your database, the table will be named yourprefixname_options. Now, the rows within that table will be shown in the central part of your screen. Under the column option_name you’ll need to locate the two rows named siteurl and home.
Then, to modify the siteurl, click on the Edit option located at the beginning of that row.
This will open a window where you can insert your siteurl. Find the Value column and add your new URL at the suggested spot. To finish, press the Go button at the edge of the window.
Edit your home URL in the same manner. Afterward, review your site frontend to make sure that everything is working properly.
Final Thoughts
There are many situations when changing your WordPress site’s URLs can come in handy. Some of the solutions we described may have seemed complicated before – after this tutorial, we hope you realized they are actually quite straightforward and take only minutes. This guide may prove to be helpful in numerous situations, so make sure you bookmark this article and keep it close if you need it again.