Search and replace is one of those WordPress tasks that looks straightforward until it goes wrong - and when it goes wrong, it can break your entire site. Whether you are migrating to a new domain, upgrading from HTTP to HTTPS, rebranding under a new company name, or simply correcting a repeated typo that appears in dozens of posts, doing this correctly requires understanding a quirk of how WordPress stores data.
When You Need Search and Replace in WordPress
The most common scenarios that call for a sitewide search and replace are:
Site migration to a new domain: When you move from olddomain.ca to newdomain.ca, references to the old domain exist throughout the database - in post content, image URLs, theme settings, and plugin options.
HTTP to HTTPS migration: After installing an SSL certificate, you need to update all hardcoded http:// references to https://. Missing even a few creates mixed content warnings that show a broken padlock in browsers.
Company rebranding: Old company name appears in dozens of posts, footer text stored in options, and widget content. A sitewide replace saves hours of manual editing.
Fixing a repeated error: A wrong phone number, a misspelled word used consistently across the site, or an old staff member's name that needs to be removed from post content.
Why You Cannot Just Use a Database Find and Replace
Here is the critical part that catches people out. WordPress stores much of its data - particularly theme customizer settings, widget configurations, plugin options, and serialized arrays - using PHP serialized format. A serialized string looks like this:
s:34:"https://www.example.ca/sample-page/";
The s:34: part is the string length. It tells PHP the string that follows is exactly 34 characters long. If you do a raw find-and-replace in phpMyAdmin and swap example.ca for newexample.ca, the URL changes from 34 characters to 37 characters - but the length value still says 34. PHP then tries to read a 34-character string and finds something different. The data becomes corrupt, and you get a broken site, blank pages, or theme settings that have simply vanished.
This is one of the most common ways that WordPress migrations go wrong when done manually through phpMyAdmin.
The Right Tool: Better Search Replace Plugin
Better Search Replace is a free WordPress plugin that handles serialized data correctly. It recalculates string lengths automatically after making replacements, so serialized data stays intact.
To use it:
- Install and activate Better Search Replace from the WordPress plugin repository
- Go to Tools > Better Search Replace
- Enter your search string (the old value) and replace string (the new value)
- Select all tables - in most cases you want to run the replacement across the entire database
- Always check "Run as dry run?" first - this shows you how many replacements would be made without actually making them
- Review the dry run results to confirm the numbers look sensible
- Uncheck "Run as dry run?" and run the actual replacement
- Deactivate and delete the plugin when you are done (it has no reason to remain active)
The dry run step is not optional. It takes an extra thirty seconds and has prevented countless accidental replacements.
Using WP-CLI for Large Databases
For very large databases - sites with tens of thousands of posts, or WooCommerce stores with large order histories - the Better Search Replace plugin can time out through the browser. In these cases, WP-CLI (the WordPress command-line interface) is the better tool.
If you have SSH access to your hosting account, WP-CLI is available on most managed hosting environments. The search-replace command is:
wp search-replace 'http://oldsite.ca' 'https://newsite.ca' --all-tables
WP-CLI handles serialization correctly, processes large databases efficiently without PHP timeouts, and gives you a clear count of replacements made. Add --dry-run to preview first, exactly as you would with the plugin.
After Running Search and Replace
Once the replacement is complete:
- Clear all caches - your hosting cache, any WordPress caching plugin, and Cloudflare if you use it
- Check your site thoroughly: homepage, a few posts, key plugin pages
- Inspect image URLs to confirm they updated correctly
- Log out and log back in to confirm the login URL is correct
- If you migrated domains, update your WordPress Address and Site Address in Settings > General
A careful, serialization-aware search and replace is a routine part of WordPress maintenance. Use the right tool and test before committing, and it is a safe, reliable operation every time.

