How to Update WordPress URLs
When changing your WordPress site's domain name or moving it from a staging site to production, updating URLs is essential to ensure all links and resources point to the correct location. Here are two methods you can use: one with a plugin and one using WP-CLI for command-line users.
Take a backup of your database before you start. Both methods below rewrite your whole database and neither can be undone.
Use one of these two tools rather than a find-and-replace in phpMyAdmin. WordPress explains why: "If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break." Both tools below understand serialized data. A raw SQL query does not.
Use one of these two tools rather than a find-and-replace in phpMyAdmin. WordPress explains why: "If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break." Both tools below understand serialized data. A raw SQL query does not.
Option 1: Using the Better Search Replace Plugin
- Install the Plugin
- In your WordPress dashboard, go to Plugins > Add New.
- Search for Better Search Replace. (Manual Install Link)
- Install and activate the plugin.
- Run a Search and Replace
- After activation, go to Tools > Better Search Replace.
- In the Search for field, enter your old URL (e.g.,
staging.example.co.uk). - In the Replace with field, enter the new URL (e.g.,
example.co.uk). - Select the database tables to update (typically all tables).
- Dry run first to check how many fields will be changed without making actual modifications.
- If the results look good, uncheck the "Dry Run" box and click "Run Search/Replace."
- Clear Cache
- After completing the replacement, clear any cache (both on your website and server) to ensure changes reflect immediately.
Option 2: Using WP-CLI over SSH
If your package includes SSH, you can run WP-CLI commands directly on the server. SSH is available on every plan except Amethyst.
- Connect over SSH:
- SSH is not switched on by default - enable it from My Services in your client area first.
- Connect using your home server name and port 722, not the usual port 22.
- Access Your WordPress Directory:
- Navigate to your WordPress root directory (usually
~/public_html) by entering:
cd ~/public_html
- Navigate to your WordPress root directory (usually
- Preview the changes first (dry run):
- Run the command with
--dry-runto see how many rows would change, without touching the database:
wp search-replace 'staging.example.co.uk' 'example.co.uk' --all-tables-with-prefix --skip-columns=guid --dry-run
- Run the command with
- Run the URL update:
- If the preview looks right, run the same command again without
--dry-run:
wp search-replace 'staging.example.co.uk' 'example.co.uk' --all-tables-with-prefix --skip-columns=guid
--skip-columns=guidmatters. WordPress is explicit that you must never change the GUID column - it is how feed readers recognise a post they have already shown, so rewriting it makes every post on your site appear brand new to every subscriber.--all-tables-with-prefixcovers tables belonging to this WordPress install. Avoid--all-tables, which rewrites every table in the database regardless of prefix - including any other application sharing it.
- If the preview looks right, run the same command again without
- Clear Cache:
- After running the command, clear your website cache (if any) to ensure the changes take effect immediately.