6. Handling Serialized Data After URL Changes (Better Search Replace)
When changing URLs in the database, a simple find-and-replace can break data that’s stored in serialized format (a common storage format in WordPress options and widget data). Serialized data includes the string length of stored values, so if a URL length changes, the serialization needs to update too. For example, replacing “oldsite.com” with “newsite.com” changes the character count, and if not done carefully, it can corrupt the entry, causing plugin settings or widgets to break.
To safely update all instances of the old URL to the new URL in the database, use a tool that understands serialization. Fortunately, there are WordPress plugins and tools designed for this. A highly recommended one is the Better Search Replace plugin. Using Better Search Replace Plugin: Install and activate the Better Search Replace plugin on the new site (you can do this via WP Admin, or download the plugin files and upload them to wp-content/plugins/ if you can’t access admin yet). In WP Admin, go to Tools -> Better Search Replace. In the plugin interface, you’ll specify a search string and a replace string. Use your old site URL (e.g., oldsite.com) as the search, and your new site URL (newsite.com) as the replace. Select all tables (or at least all tables where URLs might appear – usually all WordPress tables). Run it as a dry run first (the plugin has a checkbox for “Run as dry run”) to see how many replacements it would make, without actually changing data. If the results look plausible, uncheck dry run and run again to perform the replacements. This plugin will handle serialized fields properly, ensuring data integrity
The Better Search Replace plugin provides a user-friendly interface to find all occurrences of the old URL in the database and replace them with the new URL, while safely handling serialized data. Using Better Search Replace will update URLs inside page content, widget data, settings, etc. For instance, image URLs in your posts that pointed to oldsite.com/wp-content/uploads/... will be changed to newsite.com/..., ensuring media and links aren’t broken. It will also catch things like GUIDs in the posts table, old domain references in some plugin options, and so on.
Alternate Tools: In lieu of a plugin, developers sometimes use WP-CLI’s search-replace command (which also handles serialization) or the third-party Search and Replace for WordPress Databases script
then run without --dry-run to execute. This does essentially the same job. The plugin method is more accessible via a UI.
After running the search/replace, your new site’s database should have no references to the old domain (except perhaps in places like backup plugin records or historical data). At this point, if you visit the site on the new server’s URL, all links should point correctly to that URL. This is a major step in avoiding broken links or mixed content issues.
Note: If you kept the same domain name and are only changing hosts, you do not need to do a domain search-replace (since the domain is identical). However, if the site was in a different subdirectory on the old server and now in root (or vice versa), or if the URL protocol changed (http to https), a similar search-replace might be needed for those scenarios. Always back up the DB before running mass search-replace just in case.
Discover more from TechBooky
Subscribe to get the latest posts sent to your email.







