When migrating a WordPress site to a new domain, you’ll have to update every instance of the site’s URL in the database. Some developers prefer to use tools like WP-CLI or WP Migrate DB to handle this, while others opt for a general database search and replace plugin with a UI in the WordPress admin.
Search and Replace is an old plugin, with nearly a million downloads, that can be used to update URLs and text in the database. I used this plugin successfully for a number of years, but it went without any updates for long time. It has since come under new ownership, although the screenshots demonstrate just how long ago the plugin was released.
Better Search Replace is a new take on database search and replace plugins. It was heavily based on Interconnect/It’s open source Search Replace DB script that performs replacement actions without damaging PHP serialized strings or objects. I’ve used this script a number of times with success, although it’s not as convenient as a plugin. The Better Search Replace plugin packages it up using native WordPress database functions and adds a friendly UI.
The plugin merges the best features from older plugins and the Interconnect/It script to support the following capabilities:
- Serialization support for all tables
- The ability to select specific tables
- The ability to run a “dry run” to see how many fields will be updated
- No server requirements aside from a running installation of WordPress
Since searching and replacing in the database is a sensitive action to perform, the “dry run” feature gives you a good idea of what you can expect before pulling the trigger. Even with the option of performing a dry run, you will undoubtedly want to have a backup of your database created before touching it.
Migrations aren’t the only reason for this type of plugin. Perhaps you’ve renamed your company or product line and need to replace all instances throughout your website. This plugin makes it safe and easy to perform the replacements directly within the WordPress admin. I tested it on a development site and found that it is fast and works exactly as advertised.
Better Search Replace was created by Matt Shaw, author of the Revisr plugin that allows developers to synchronize WordPress with a remote Git repository. If you’re a long-time fan of the Interconnect/It script, you’ll find that this plugin is even easier to use. You can find Better Search Replace on WordPress.org.
Timesaver, just changed domain for one web and starting changing pictures urls in database … Then remembered that I read today something here :D so install it fast and easy changed about 60 urls with few clicks. Much better than do it one by one :D
Thanks to developer for great plugin and thanks to Sarah, that posted about it here.