How To WordPress Search And Replace - 3 Methods

How To WordPress Search And Replace – 3 Methods

Sometimes using WordPress, we want to search and replace everywhere easily. Maybe you want to change all URLs to a specific domain, and you want to search and replace a keyword or simply rename some keywords which have shifted in your SEO strategy.

You can easily install the WordPress plugin Better Search Replace. Once installed, access the plugin and enter the text to search for and the text to replace it with. Choose all tables in the list and press Run Search/Replace. This is the most secure way of doing it.

This is, however, not the only way of doing it. There are 2 other methods to search and replace in your WordPress website, but let me elaborate first on the Better Search Replace plugin method.

1. Use a WordPress plugin to search and replace

By using a plugin you ensure your own safety. Messing with the database directly, if you don’t know what you’re doing, can make your entire website crash. So if you want a safe way to search and replace your WordPress website, then this is the best method.

There are other plugins than Better Search Replace, such as Real-Time Find and Replace, Search Regex and Search & Replace. But based on my own experience and testing, then Better Search Replace is the easiest and safest plugin to use right now.

Even though using a plugin is the safest way, you can still make mistakes by searching and replacing, so I always recommend you take a backup of your WordPress website before you start on these actions. I have made a guide of 3 easy ways to back up your WordPress website.

[cboxarea id=”cbox-DZ7YzH84qT48YAf1″]

2. Run a MySQL query to search and replace

If you’re experienced with MySQL and/or PHPMyAdmin, then this solution might be for you. By doing it this way, you avoid installing a plugin, and if familiar, then it’s a very fast method to search and replace on your WordPress website.

Sign in to your PHPMyAdmin or via your MySQL client on your computer. Choose your database, and if you’re in doubt about which database is the right one, then you can on your server see it in the wp-config.php file. Just open it up and search for: DB_NAME.

After this then, click on the SQL tab or the query tab, depending on your program, and then enter the following query:

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'Replace this text', 'With this text')

Now here, you need to replace the two words “TABLE_NAME” and “FIELD_NAME”. The table name needs to be replaced with the table in which you want to replace the text. The field name needs to be replaced with the field name where the text is in the table.

This is a very tedious process, but it’s the most precise process if you only want to replace the text in a specific table in a specific field. Again remember to back up your WordPress website before you run any of these commands.

Based on my own experience, I only use this solution when I know where the text is, and I don’t want to replace it on the entire website but only in a specific table in the database. Otherwise, I always use a plugin to do it for me.

3. Use WP-CLI to search and replace

If your website is set up with WP-CLI or your host provides access via an SSH connection to your website, then you can also search and replace using the WP-CLI. If you have never heard of the WP-CLI, then this isn’t the solution for you.

Let’s assume I had written WordPress wrong on my own blog. To search and replace using the WP-CLI, simply open up your terminal, connect to your WordPress website and enter the following command:

wp search-replace 'wordpress' 'WordPress' --precise --recurse-objects --all-tables

Again if you know what you’re doing using the WP-CLI, then this solution is very straightforward, but again be careful and make sure to back up your WordPress website before you start doing anything like this.

If you want more information about the WP-CLI or maybe just this command specifically, then you can read about it on WP-CLI’s website in their official documentation of the search and replace command.

Conclusion

I just want to sum up the 3 methods up here. It’s important you choose the method you feel most comfortable with, and whatever method you choose, your first step should always be to back up your WordPress website.

If you’re not a developer, and MySQL and WP-CLI don’t sound familiar, I would strongly recommend method 1 using a plugin. If you only want to replace something specific in one database table, then the MySQL method is the right choice for you.

The WP-CLI is excellent if you work with it on a daily basis, and know how to easily connect to your WordPress website and run commands.

FAQ

What is the best find and replace plugin in WordPress?

It is without a doubt Better Search Replace. Not only has it been downloaded more than a million times, but it’s free to use and super easy. Install the plugin in your WordPress admin area, access the plugin, enter the text you want to replace and what to replace it with. Then select all the tables in the list and run the search and replace.

How do I replace a string in content in WordPress?

For this you can use the Better Search Replace plugin. Simply install and access the plugin. Enter the string you want to search for and the string you want to replace it with, and then run the search and replace.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *