How to change a WordPress site URL
Three ways to change the WordPress site URL, and why a search-and-replace on the database is usually still required afterwards.
WordPress stores its own address in two database fields — siteurl and home — and refers back to them constantly. Change the domain or path a site lives at without updating these, and you get redirect loops, an admin area that will not load, or a site that redirects to the address it used to have.
There are three ways to make the change, in order of how badly stuck you are.
Method 1: from the dashboard
The normal route, if you can still log in.
-
Go to Settings, then General
You will see two fields: WordPress Address (URL) and Site Address (URL).
-
Update both fields
These correspond to
siteurlandhome. For almost every site they should be identical. They only differ in the specific case of running WordPress from a subdirectory while serving the site from the domain root — see moving WordPress out of a subdirectory if that is your situation. -
Save changes
WordPress will redirect you back to the login page under the new address, since the session that was active is now tied to a URL that no longer matches.
Method 2: from wp-config.php
Use this when the dashboard itself will not load correctly, or you would simply rather set it outside the database. Add these two lines above the "stop editing" comment in wp-config.php:
define( 'WP_HOME', 'https://www.yourdomain.com' );
define( 'WP_SITEURL', 'https://www.yourdomain.com' );
These constants override whatever is stored in the database without changing the stored values themselves, which makes this the safest option when you are not sure yet what the final address should be — nothing here is permanent, and removing the two lines reverts to the database values.
Always write the full address including https://. A value missing the protocol, or mixing http:// and https:// between the two settings, is a common cause of a site that loads but with broken CSS and JavaScript.
Method 3: directly in the database
Needed when you cannot reach wp-admin at all — the wrong URL is itself the thing preventing login, for instance, which is a common cause of a login redirect loop after a migration.
-
Open phpMyAdmin
Found in the databases section of your control panel — see using phpMyAdmin.
-
Open the wp_options table
Sort or search by the
option_namecolumn forsiteurlandhome. -
Edit each row's option_value
Change it to the correct address for both rows and save.
If the install uses a custom table prefix set at installation, the table will be named accordingly — for example wp7x2_options rather than wp_options. Check wp-config.php for the value of $table_prefix if you cannot find wp_options.
Why this alone is often not enough
Updating siteurl and home fixes where WordPress itself thinks it lives. It does not touch the old address if it is hardcoded anywhere else in the content — inside post content, image URLs saved with a full path, widget settings, or a page builder's saved data. That is extremely common after a domain change or a migration, and it shows up as images that will not load or internal links that point back at the old domain.
The fix is a search-and-replace across the database, swapping every occurrence of the old address for the new one. This has to be done carefully, because a plain text find-and-replace can corrupt WordPress's serialized data if it is not aware of the length prefixes that format uses. See searching and replacing inside a database for the safe way to do this, including tools built specifically to handle serialized data correctly.
Checking it actually worked
- Load the homepage in a private browser window and confirm the address bar shows the address you expect, with no redirect back to the old one.
- Log into wp-admin and check the URL fields under Settings, General, match what you set.
- View the page source and confirm CSS and JavaScript files are being requested from the new address, not the old one.
- Click through to an old post or page and confirm any internal links go to the new domain.
If you are stuck in a redirect loop after changing the URL
A mismatch between what is stored in the database, what is set in wp-config.php, and what a caching plugin or the browser has cached is the most common cause. Clear any page cache, try a private browser window, and confirm the two settings agree with each other rather than fighting. Fixing a WordPress login redirect loop covers this specific failure in detail if the steps above have not resolved it.
Related reading
Submitting the login form just bounces you back to it — usually a URL mismatch, cookie problem, or a plugin, worked through in order.
How to search and replace inside a databaseA plain find-and-replace can silently corrupt serialized data — here is how to do it without breaking the site.
How to use phpMyAdminOpening phpMyAdmin from your control panel and using it to browse, edit, import and export a database.
How to move WordPress to a new hostCopy the files and database across, update the configuration, test before anyone sees it, then switch DNS with the old site still live.