If you’re using Google Docs, Google Spreadsheets, and Microsoft Word Document, you’re certainly familiar with the function Search and Replace. That happens when you try to look for a repeated word or phrase on multiple pages then remove or use another one instead of this word or phrase.
Similar to the above tools, WordPress also enables you to search and replace databases on your site. You can quickly find a text, image, or even a URL and replace it with a new one.
In a matter of fact, WordPress doesn’t make it easy for users to filter and replace data. You have to use code or seek help from a third-party tool. That’s why we put together this tutorial clearly showing you how to perform database search and replace across your WordPress site. Before digging into the detailed guide, we’d like to break down some common cases of when you need to apply this powerful function.
When Should You Search and Replace WordPress Database?
Searching and replacing isn’t always ideal. It’s significant to clearly understand in which situation you need to use this option to update your database.
- Improve SEO – You have several posts about a certain topic. However, they’re not ranking anywhere since you’re targeting a no-to-low search volume keyword. It’s recommended to replace this one with a higher volume keyword that has the same meaning. As a result, Google can easily clarify your main content and rank your content better.
- Correct typo errors or grammatical mistakes – Before getting published, each article must be reviewed and edited carefully. However, your team sometimes makes the mistake of using the wrong word repeatedly without noticing. Once you figure out, this incorrectness has occurred across your site. Fixing one by one is time-consuming though. It’s where the Search and Replace feature comes in handy.
- Replace unprotected URLs – This case seems rare but it still happens somehow. At the time you secure a media file that is already embedded in your content, its original URL is changed into the protected link. If this file is used in numerous posts in other posts before, you have to update them too. The search and replace solution enables you to look for the unprotected links of a specific file and replace them with the protected ones.
Ways to Search and Replace Database in WordPress
You have multiple options when it comes to search and replace methods in WordPress. In fact, you can use the “Ctrl + F” keyboard combination to discover text on a page. What if you have hundreds of pages that need processing?
Manually going through every page and post and editing each of them would drive you crazy and exhausted. You sometimes miss some occurrences too. On top of that, it’s impossible to use “Ctrl + F” to find links.
Besides that, be careful if you decide to update your database by hand since it involves a large number of data tables. This could be a challenge for developers with professional coding knowledge too.
In addition, touching the database might risk your site performance. Just a minor incorrect change can create potential conflicts as well as damaging your database.
We recommend using a plugin to simplify the process.
Use Better Search Replace Plugin
Receiving over 1 million active installations with 4.5-star ratings, you can imagine how powerful Better Search Replace is in finding data and replacing it with others.
The plugin will visit your selected tables, then make a “dry run” to figure out how many fields should be updated. Unlike other plugins, it doesn’t require access to your WordPress server.
The simple “Settings” page makes it easy for you to configure your WordPress search and replace feature. To get started with the plugin, all you need to include:
- Going to Add New under Plugins in your WordPress dashboard
- Type “better search replace” in the keyword box
- Install and activate the plugin
- Head to Tools and choose Better Search Replace option
- Enter the text or URL you intend to look for as well as the one you want to display in the Search for and Replace with boxes
- Select the database tables you want to clarify
- Hit Run Search/Replace
Better Search Replace plugin supports multisite too. This allows you to either run “search” and “replace” on all tables from the main site dashboard or on a single subsite only.
Be careful when performing a search and replace because you will damage your WordPress database if you enter an incorrect string. You must also back up your data before taking any action.
You sometimes see a white screen while running a search and replace using Better Search Replace plugin. To fix this, simply head to the Settings tab and decrease the Max Page Size level.
Use Prevent Direct Access Gold Plugin
Primarily coming as a media file protection plugin, Prevent Direct Access Gold enables you to find and auto-replace the unprotected file URLs with the protected links in certain pages and posts.
The following guide shows you how to use the plugin for WordPress media file search and replace feature:
- Download Prevent Direct Access Gold plugin
- Open Plugins → Add New in your admin dashboard and click Upload Plugin
- Choose the file you have downloaded
- Install and activate the plugin
- Head to the plugin Settings page on the navigation menu
- Scroll down to the feature Search & Replace and enable it
- Pick page containing files you want to replace their URLs
- Save your changes
It’s important to identify and select exactly pages you want the plugin to find and replace unprotected URLs in their content.
Use a MySQL Query for WordPress Search and Replace
This method is for those who are comfortable with code and don’t like adding plugins to their WordPress site. To do it, you need to:
- Log into your cPanel hosting and choose phpMyAdmin in the DATABASES section
- Click on your WordPress database name and then SQL
- Enter the SQL query in the below format
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'Text to find', 'text to replace with');
- Replace the TABLE_NAME and FIELD_NAME with your specific WordPress table and file names
- Hit Go to continue
Ready to Run Search and Replace for Your WordPress Site?
It’s necessary to maintain the WordPress database periodically, and one of the most basic ways is to search and replace data. You can find and replace low-search volume keywords, typo errors, or even unprotected links.
There are several solutions you can apply to perform find and replace text and URLs in your WordPress content. Seek help from an additional plugin if you don’t get familiar with coding.
Among thousands of plugins available on the WordPress repository, we recommend installing Better Search Replace plugin for the text search and replace function due to its effectiveness and simplicity. Intend to filtering unprotected image URLs? Prevent Direct Access Gold should be your ideal solution.
You’re also able to sue the MySQL Query too. This way forces you to log into your cPanel and few lines of code.
Still have a question on how to perform search and replace in WordPress? Or simply want to share which of the above is your favorite solution? Let us know in the comment section below.