When it comes to managing your WordPress website, making minor changes here and there isn’t usually a big deal. However, sometimes you need to update many elements on your site at once, in which case a WordPress search and replace may be necessary.
Perhaps you just migrated from HTTP to HTTPS, for example, and you need to update all of your hard-coded HTTP URLs in the WordPress database. Alternatively, maybe 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 save you a lot of time.
In this post, we’ll explain what a WordPress search and replace is and when conducting one might be necessary. Then we’ll walk you through five different ways you can do this.
Let’s get started!
Prefer to watch the video version?
An Overview of WordPress Search and Replace
There are a handful of situations in which you may need to perform a search and replace on your WordPress site. One of the most common scenarios is when you want to replace a piece of text (such as a disclaimer or bio) that you added to multiple pages or posts, but you don’t know every place it’s currently located.
Being able to conduct a mass search and replace saves a lot of time, in contrast to manually searching every post and page for the text you want to switch out. Plus, you can use this technique on more than just text.
For instance, you can also perform a mass WordPress search and replace for URLs and images in your WordPress database. This functionality comes in handy if you want to:
- Update your Search Engine Optimization (SEO) keywords
- Correct a grammatical or spelling issue
- Remove certain words or special characters
- Update your HTTP URLs to HTTPS after a migration
- Move your site from www to non-www URLs (or vice versa)
- Update old shortcodes, content, or strings of text
One thing we want to mention is that there’s no ‘undo’ option. Once you replace the text or other content, you can’t get the old version back. You would have to do another mass search and replace in order to reverse the process. That’s why we strongly suggest performing a backup before any WordPress search and replace routine.
How to Perform a WordPress Search and Replace (5 Methods)
There are a lot of different ways to perform a WordPress search and replace. Let’s take a look at five recommended options.
1. Use MyKinsta’s Search and Replace Tool
If you are a Kinsta customer, you can use our own search and replace tool. It’s available right within the MyKinsta dashboard. To locate this tool, navigate to Sites, and then click on the name of the website you want to run the search and replace on:
Next, select Tools and navigate to the Search and Replace option:
As we mentioned earlier, there are a number of different operations you can use this tool for. In this example, we’ll be changing some URLs that use “http” to ones using “https”.
In the search field, enter the value you want to look for in the database, and hit Search. The search and replace tool will display the number of occurrences for the given string:
Check the Replace box to continue with the process. In the Replace with field, enter the new text, URL, or other value:
We recommend leaving the Clear cache when ready box checked, to automatically purge your site’s cache after the search and replace process. That way, visitors will see the updated version of your website right away. Then, click on the Replace button.
After the WordPress search and replace is complete, you’ll see a confirmation dialog showing the number of replacements that were processed. When you’re done, select Cancel to exit the search and replace tool. That’s it!
2. Install a WordPress Search and Replace Plugin
If you’re not hosting at Kinsta, or you want another option to perform a WordPress search and replace without manually searching your database, you can also use a plugin. One popular solution you can use for this is Better Search Replace:
The Better Search Replace plugin is developed by the WordPress team over at Delicious Brains, and is inspired by the interconnect/it PHP script, which we’ll mention in the next method.
Some of Better Search Replace’s features include:
- Serialization support for all tables.
- The ability to select specific tables.
- The option to conduct a ‘dry run’ to see how many fields will be updated.
- No server requirements, aside from a running installation of WordPress.
- WordPress multisite compatibility.
There are hundreds of different use cases for this tool. As you can see you in our example below, in the Better Search Replace options you could easily search for any hard-coded HTTP references and update with the HTTPS versions:
There is also a pro version of the plugin available, which gives you access to even more features. You can check out the official documentation on how to better use this plugin.
Another tool you might consider using is Search Regex:
While it’s sufficient for performing basic search and replace tasks, including updating URLs and content in bulk, this plugin is not as popular or widely used as Better Search Replace. Still, it’s an actively-maintained and well-rated tool that can get the job done, and it’s simple to use.
You can download either solution from the WordPress repository. Alternatively, you can search for them within your WordPress dashboard under Plugins > Add New.
3. Use the interconnect/it Search Replace DB PHP Script
You may not want to install another plugin on your WordPress site. If so, another way you can perform a WordPress search and replace is to use a free PHP script from interconnect/it called Search Replace DB:
It’s important to note that using this script could break your WordPress website if you don’t know what you’re doing. If you are not comfortable with this method, please check with a developer or your web host first.
This script has been around since 2011, and the developers actively update it. To use the script, simply download the zip file, extract the folder called “search-replace-db-master”, and rename it to something of your choosing.
In our example, we renamed it to “update-db-1551”:
Next, upload the file via FTP or SFTP, 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. However, you must check to ensure that the details are correct and that they are the right ones for the database you wish to carry out a search and replace operation on.
You can click on dry run first to see what the script will be updating or replacing. When you’re ready, select live run, which will perform the database updates and the WordPress search and replace:
Also, for security reasons, it’s very important that you delete this script after you are done! You can select the delete me button to do this.
Need a hosting solution that gives you a competitive edge? Kinsta’s got you covered with incredible speed, state-of-the-art security, and auto-scaling. Check out our plans
If you don’t, it could leave your website open to attacks. It is also best to double-check your web server to confirm that the folder and script have been completely removed.
4. Perform the Search and Replace Directly With WP-CLI
Another method you can use to perform a WordPress search and replace is to do it directly with WP-CLI. This is an option for the WordPress developers out there.
To Kinsta 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 and a curated list of useful SSH commands.
Here is an example of what the command looks like:
wp search-replace 'http://example.dev' 'http://example.com' --precise --recurse-objects --all-tables
You can read more about the parameters available to you for the wp search-replace command in the official WP-CLI documentation. You may also want to check out this advanced search and replace WP-CLI guide.
5. Run a Find and Replace MySQL Query With phpMyAdmin
If you are comfortable working with code and would prefer not to use a plugin to perform a search and replace in your WordPress database, you can also use MySQL query in phpMyAdmin. However, this should only be done by professional WordPress developers.
If your hosting provider uses cPanel, then you can browse to and select phpMyAdmin under Databases:
Kinsta customers can access phpMyAdmin directly from the MyKinsta dashboard. To do this, click on your site first. Then under the Info tab, scroll down to the Database access section and click on Open phpMyAdmin:
A new tab will open with the phpMyAdmin login page. Enter your database username and password, then select Go:
Once you’ve accessed phpMyAdmin, locate your database’s name. If you need help doing this, navigate to your File Manager. Under the public_html folder, open your wp-config.php file, and look for the line that reads “define(‘DB_NAME’, ‘Database Name‘);”.
Next, from phpMyAdmin, select the SQL tab:
Add the following code snippet:
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'Text to search, 'Text to replace it with');
Then click on the Go button to run your SQL query. When the process is done, it will display a success message indicating the number of changed instances. You can visit your WordPress site to confirm that the search and replace was successful.
Whether you’re looking to update your keywords or replace a specific piece of text on all your posts, learning how to perform a mass search and replace is incredibly helpful. Fortunately, there are multiple methods you can use to do this.
Five techniques we recommend using for a WordPress search and replace include:
- Use our own search and replace tool in your MyKinsta dashboard.
- Install a WordPress search and replace plugin, such as Better Search Replace or Search & Replace.
- Use the interconnect/it Search Replace DB PHP script.
- Perform the search and replace directly using WP-CLI.
- Run a MySQL query with phpMyAdmin.
Save time, costs and maximize site performance with:
- Instant help from WordPress hosting experts, 24/7.
- Cloudflare Enterprise integration.
- Global audience reach with 32 data centers worldwide.
- Optimization with our built-in Application Performance Monitoring.