As your website grows, sometimes you end up coming across some really bad habits, or have strange characters come up. Sometimes you also may use plugins that produce shortcodes, and then later on need to replace them. Some of those habits or shortcodes can extend across several hundred posts. That means you have to go and edit each one, right?
Not necessarily. In this tutorial, we’re going to cover how to find and replace text in WordPress. I’m going to give both an easy tool for those who don’t want to muck with SQL queries, and also a way to do so directly in the MySQL database.
Please note that before you proceed to find and replace text in WordPress site using any of the methods mentioned below, you should generate a backup of your website.
How to Find and Replace Text In WordPress – With a Plugin
Search and Replace
The Search and Replace plugin has a lot of options to choose from in finding and replacing whatever text or strings you want. It’s a matter of simple filling out what you need to find, what you want to replace it with, and selecting where you are replacing it.
The Search Regex form is a lot simpler than Search and Replace. Simply fill the form and select what you’re trying to find and replace.
How to Find and Replace Text In WordPress – Using MySQL database
For those not afraid to open MySQL, you can find and replace text using the following general string. Just replace the areas that are capitalized with the correct info.
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME,'TEXT YOU WANT TO FIND','TEXT YOU WANT TO REPLACE IT WITH')
As an example- Perhaps you kept writing WP instead of WordPress throughout your website’s post content. In order to correct that, alter:
1. TABLE_NAME with wp_posts because that is the correct table for your posts
2. FIELD_NAME with post_content because the post content is where that content you need to replace is at
3. TEXT YOU WANT TO FIND with WP
4. TEXT YOU WANT TO REPLACE IT WITH with WordPress
Your query string in MySQL will look like the following:
update wp_posts set post_content = replace(post_content,'WP','WordPress')
Here’s a screenshot of the query.
Just click on the button that says ‘Go’ and it will perform the query for you.
So, these are just some of the ways you can find and replace text in WordPress. Hope this helps!