You can search and replace old URLs with new ones in a WordPress database to ensure your site functions correctly after a domain change or migration. This process is performed by a Site Administrator and requires access to the WordPress dashboard or a database management tool.
Important: Performing a search and replace on a database can cause permanent data loss if done incorrectly. Always perform a full backup of your website and database before proceeding.
Before you begin
You will need:
Site Administrator access to the WordPress dashboard.
A full backup of your website and database.
A list of the old URLs and the new URLs you intend to replace.
Search and replace using a plugin
The safest and most common method for a Site Administrator to perform a search and replace is by using a dedicated WordPress plugin. This method handles the serialization of data, which is necessary to ensure that your site's configuration remains intact.
Log in to your WordPress dashboard.
Navigate to Plugins > Add New.
Search for a "Search and Replace" plugin (such as "Better Search Replace").
Install and activate the plugin.
Navigate to the plugin's settings page (usually under Tools).
Enter the old URL (e.g.,
http://old-domain.com) in the Search for field.Enter the new URL (e.g.,
https://new-domain.com) in the Replace with field.Select the tables you wish to search (selecting all tables is standard for a migration).
Choose whether to perform a Dry Run first. A dry run will tell you how many occurrences were found without making changes.
If the dry run is successful, run the actual search and replace.
Search and replace via WP-CLI
If you have SSH access and are comfortable using the command line, WP-CLI is a highly efficient way to perform a search and replace.
Warning: This method directly modifies the database. Ensure you have a fresh backup before executing these commands.
Connect to your server via SSH.
Navigate to your WordPress root directory.
Run the following command to perform a dry run:
wp search-replace 'http://old-domain.com' 'https://new-domain.com' --dry-run
If the results are correct, run the command without the dry-run flag:
wp search-replace 'http://old-domain.com' 'https://new-domain.com'
Confirm the result
After the search and replace is complete, verify the changes by performing the following checks:
Visit the website and ensure that internal links point to the correct domain.
Check that images and other media assets are loading correctly.
Verify that the site's "Home" and "Site" URLs are correct in Settings > General.
If the site displays broken images or links
If some assets are still pointing to the old URL, it may be due to a caching layer.
Clear your site cache: If you use a caching plugin (like WP Rocket or W3 Total Cache), clear the cache entirely.
Clear your server cache: If your hosting plan includes a server-side cache (like LiteSpeed or Varnish), clear that cache through your hosting control panel.
Clear your browser cache: Open your site in an Incognito or Private window to ensure you are not viewing a cached version of the page.
Limitations
Serialized Data: Do not use a standard SQL query (via phpMyAdmin) to perform a search and replace unless you are certain the data is not serialized. Standard SQL queries can break serialized data, which often causes widgets or page builder layouts to disappear.
Scope: This procedure does not automatically update external links on other websites that point to your site.
