Depending on your circumstances, sometimes you need to update things in bulk on your WordPress website. Perhaps you just migrated from HTTP to HTTPS and you need to update all your hard-coded HTTP URLs in the database. Or perhaps you are changing domains and need to update all the database references. There are many scenarios in which knowing how to perform a bulk WordPress search and replace can come in very handy. It can also save you a lot of time, sometimes even hundreds of hours!
WordPress Search and Replace
There are are a lot of different ways in which you can perform a WordPress search and replace. In this post, we will walk you through four different recommended options.
If you are a Kinsta client, you can use our search and replace tool that is available from right within the MyKinsta dashboard. Follow the steps below.
Under “Sites”, click on the name of the site you want to run the search and replace on.
Click on Tools, and navigate to the “Search and Replace” tool.
There are a number of different operations you can use this tool for, such as:
- Updating your HTTP URLs to HTTPS after a migration.
- Moving your site from www to non-www URLs or vice versa.
- Updating old shortcodes, content, or strings of text.
In this example, we are going to show you how to update HTTP URLs to HTTPS.
Ensure you don’t include any leading/trailing whitespace in either of the fields as this might produce undesirable results.
- In the search field, enter the value you want to search for in the database. In this case, we will use our HTTP domain:
- Click the “Search” button to run a search on the database. The search and replace tool will show the number of occurrences for the given string.
- Check the “Replace” box to continue with the replacement process. In the replace with field, enter the value that should be used to replace the value you are searching for. In this case, we will use our HTTPS domain:
- We recommend leaving the “Clear cache when ready” box checked to automatically purge Kinsta Cache after the search and replace process.
- Click the “Replace” button.
After the search and replace is complete, you’ll see a confirmation dialog showing the number of replacements processed. In our case, there were seven replacements for
Finally, click “Cancel” to exit the search and replace tool.
One of the first methods is to use a free plugin called Better Search Replace.
The Better Search Replace plugin is developed by the awesome WordPress team over at Delicious Brains and is inspired by the interconnect/IT PHP script in option 2 below. These guys know a thing or two about WordPress development. As of writing this, the plugin currently has 300,000+ active installs with a 4.5 rating. It is also actively maintained. You can download it from the WordPress repository or by searching for it within your WordPress dashboard under “Add New” plugins. Some of the features include:
- 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
- WordPress Multi-site support
There are hundreds of different use case scenarios. As you can see you in our example below, in the Better Search Replace options, we could easily search for any hard-coded HTTP references and update with the HTTPS version.
There is also a pro version of the plugin available which gives you even more features. You can check out their official documentation on how to better use the plugin.
A second option you have for running a WordPress search and replace is to use a free PHP script from interconnect/it called Search Replace DB.
Using this script could break your WordPress website if you don’t know what you are doing. If you are not comfortable doing this, please check with a developer or your web host first.
This script has been around since 2011 and the developers actively update it. Interconnect/it is known for its great WordPress consulting work and development. To use the script, simply download the zip file, extract the folder called search-replace-db-master, and rename it to something secret of your choosing. In our example, we renamed it to update-db-1551. Then upload it via FTP, SFTP, or SCP to your web server’s public directory. This is typically the same directory that contains your /wp-content folder. Then navigate to your secret folder in your browser, such as https://domain.com/update-db-1551.
The script will automatically attempt to find and populate the database field but you must check that the details are correct and that it is for the database you wish to carry out a search/replace operation on. You can click on “dry run” first to see what it will be updating/replacing. Then when you are ready click on “live run” which will perform the database updates and the WordPress search and replace.
It is also very important due to security reasons that you delete this script after you are done! You can click the “delete me” button. It you don’t, it could leave your website open to attacks. It is also recommended to double check on your web server and confirm that the folder/script has been completely removed.
And finally, the last recommend method for performing a WordPress search and replace is to do it directly with WP-CLI. This is for you WordPress developers out there. For our Google Cloud customers, we provide SSH access so you can use WP-CLI. If you are unfamiliar with WP-CLI you can check out our in-depth post on managing WordPress from the terminal.
Here is an example of the command:
wp search-replace 'http://example.dev' 'http://example.com' --precise --recurse-objects --all-tables
If you enjoyed this tutorial, then you'll love our support. All Kinsta's hosting plans include 24/7 support from our veteran WordPress developers and engineers. Chat with the same team that backs our Fortune 500 clients. Check out our plans