Changed domain? Updating old URLs inside WordPress safely
Short answer: Changing the domain in Settings → General doesn't update the old address stored inside posts, widgets and theme settings. To fix those, run a search-and-replace that understands serialised data, such as WP-CLI's wp search-replace or a dedicated plugin, never a plain find-and-replace on a database export. Back up first, do a dry run, skip the guid column, then replace. Finally, redirect the old domain to the new one so visitors and search engines follow.
You've moved from oldname.co.uk to newname.co.uk, or from a staging address to the live one, and the site mostly works. Then you notice images loading from the old domain, buttons pointing to dead links and a slider that has lost its settings. The cause is almost always the same: the old address is still stored throughout the database. This guide walks through fixing it safely.
Why the old domain hangs around
WordPress stores two key addresses in Settings → General: WordPress Address (URL), where the core files live, and Site Address (URL), what visitors type. WordPress's migration handbook says both should include https:// and have no trailing slash.
Changing those fields doesn't rewrite the rest of the database. The handbook says it plainly: references to the old domain remain in the database after a move and can cause problems with links or theme display. Full URLs end up inside post content (every image you inserted), custom fields, widget settings, page builder data and theme options.
Why a plain find-and-replace breaks things
The tempting shortcut is to export the database as a SQL file, find-and-replace the domain in a text editor and import it again. The handbook warns against exactly this: some themes and widgets store values with the length of the URL recorded, a format called serialised data. Change the URL's length without updating that count, and those settings break. That's why sliders, menus and widgets often go blank after a careless replace.
The handbook lists three ways around the problem: a plugin built for it (it names Velvet Blues Update URLs and Better Search Replace, if you can access the dashboard), WP-CLI's search-replace command, or a third-party database script for people comfortable with database administration.
Step 1: Take a full backup
Download the site files and export the database. Store both somewhere other than the server. Everything that follows changes many rows at once; a backup is your undo button.
Step 2: Confirm the new addresses in Settings → General
Make sure WordPress Address and Site Address show the new domain with https:// and no trailing slash. If you can't reach the dashboard because the addresses are wrong, the handbook describes other ways to set them, such as constants in wp-config.php.
Step 3: Decide exactly what to search for
Be precise. If the old site was https://www.oldname.co.uk, search for that full string. Including the protocol and host avoids accidentally changing unrelated text that happens to contain "oldname". Check whether some content used http:// or the non-www version too; you may need more than one pass.
Step 4: Do a dry run
WP-CLI's documentation describes a --dry-run option that runs the whole operation and shows a report without saving changes. Run something like:
wp search-replace 'https://www.oldname.co.uk' 'https://www.newname.co.uk' --skip-columns=guid --dry-run
Read the report. It shows which tables and how many replacements would be made. If the numbers look wildly high, or tables appear that you didn't expect, stop and check your search string.
According to the WP-CLI docs, the command handles PHP serialised data and doesn't change primary key values; tables without a primary key are skipped. By default it searches tables registered with WordPress. On multisite it covers only the current site unless you add --network. Options like --all-tables-with-prefix widen the scope to plugin tables that aren't registered.
Step 5: Leave the GUID column alone
The --skip-columns=guid part matters. WordPress's handbook explains that the guid column in the posts table holds a permanent unique identifier, used mainly by feeds so feed readers know whether they've already shown an item, and that you must not change it. The WP-CLI documentation's first example uses exactly this skip. If you use a plugin, look for an equivalent option to skip GUIDs.
Step 6: Run it for real
Remove --dry-run and run the command. If you prefer a reviewable file instead of changing the live database, the docs describe an --export option that writes the transformed data as an SQL file.
No WP-CLI access? Many hosts provide it over SSH; otherwise a search-replace plugin does the same serialisation-aware job from the dashboard. Either way, the backup and dry run steps still apply.
Step 7: Clear caches and check
Flush any caching plugin, server cache and CDN cache. Then check:
- the homepage, a few posts and the contact page;
- images and downloadable files;
- menus, sliders, widgets and footer content;
- forms (including where they send notifications);
- your page builder's pages, if you use one.
Search the database again for the old domain with a dry run. A handful of leftovers may be fine (for instance, deliberate links to the old domain in an announcement post); hundreds mean a pass was missed.
Step 8: Redirect the old domain
Fixing the database doesn't help people who arrive via old links, bookmarks or search results. Keep the old domain registered and set up permanent (301) redirects from every old URL to its equivalent on the new domain, page by page rather than everything to the homepage. Then update the address on your business profiles, email signatures and anywhere else you've published it.
FAQ
Can I just change the URLs in Settings → General?
That updates where WordPress thinks it lives, but not the addresses stored inside your content and settings. You still need a search-and-replace.
Is a search-replace plugin as safe as WP-CLI?
Plugins designed for this handle serialised data too, and WordPress's handbook lists them as an option. The same rules apply: back up, dry run, skip GUIDs.
What about moving from staging to live?
Same process. Search for the staging address and replace it with the live one, after copying the site across.
Why did my widgets vanish after I replaced URLs?
Most likely a plain text replacement broke serialised data. Restore the backup and repeat the replacement with a serialisation-aware tool.
If a domain move has left your WordPress site half on the old address, tell us the old and new domains and we can plan a clean replacement and redirect map.