The Best (and simplest) Way to Search and Replace in WordPress

Sometimes, don’t you just wish you could do a simple text search and replace in a wordpress document, as you would with a word processor?

You can, with one of the various plugins. But if the plugin searches within the site database, can this be dangerous?

  • A plugin may search inside your website database to perform the search and replace process.
  • It may be a global search and replace? This is where the search replaces everything (with your search terms) in your whole site, (from inside the database). This can be dangerous if text you didn’t want changed (or shouldn’t change) is then updated.

You can do a simple search and replace without a plugin. Just follow these simple steps:

Topics in this article:


How do we Search & Replace in WordPress?

You can do this easily, within an individual WordPress Post or Page, and you don’t have to start playing around with your site database to make the changes (as some plugins do?).

The First Solution:

The only thing missing from the first solution, is ‘Replace all’, (which is not always a good idea). But you can find and replace text repeatedly…

How you can Select Text in WordPress to Search & Replace:

The Second Solution:

The second solution does do a search and replace globaly, but you have to use a code editor and cut and paste. Even though you are making the changes outside of WordPress, it’s still a simple and quick solution.

How can you do a Global Search & Replace in WordPress:


How you can Select Text in WordPress to Search & Replace?

We need to view all the text for a post or Page.

  1. Go to your WordPress Post or Page that you want to change (I’m using the latest version with Gutenberg blocks).
  2. Select the post or page you want to edit, and open it in edit mode.
WordPress Search & Replace – Edit a Post or Page
  1. On the far right hand side you will see three dots ‘Show more tools & options’.
WordPress Search & Replace - Show More Tools & Options
WordPress Search & Replace – Show More Tools & Options
  1. Click on the ‘More tools & options’ (three dots) and select ‘Code Editor’ in the Editor section. This will allow you to edit the whole post or page all at once, rather than individual blocks (it shows the post or Page in the HTML format).
WordPress Search & Replace – The Code Editor
  1. Use your browsers ‘Find’ tool (Ctrl+f) to search for the text you want.
WordPress Search & Replace – Using Find to Search & Replace
  1. Manually update the text.
WordPress Search & Replace – Edit the Text
  1. If you need to replace more items, use copy and paste and the browsers ‘find’ search controls to go to the next item.
WordPress Search & Replace – Copy the Text
  1. This allows you to only replace the items you want to change.
  2. When complete, switch back to the ‘Visual Editor’.
WordPress Search & Replace – The Visual Editor
  1. And save the document.
WordPress Search & Replace – Update
  1. Don’t forget you can undo any changes…

And that’s it. your done. You have just completed a search and replace…


How can you do a Global Search & Replace in WordPress:

You can do a global search and replace in WordPress (without a plugin). But you have to use a code editor and a bit of cut and paste. It’s not difficult, as I’ll explain how below:

Note:

You can use any text editor with search and replace to do this, but it is better to use a code editor to perform this task. If you don’t have one, there are plenty good free examples you can use, such as Visual Studio Code, or Atom Editor, etc.

What we’re basically going to do is:

View the Page in HTML:

We need to view all the text for a post or Page.

  1. Go to your WordPress Post or Page that you want to change (I’m using the latest version with Gutenberg blocks).
  2. Select the post or page you want to edit, and open it in edit mode.
WordPress Search & Replace – Edit a Post or Page
  1. On the far right hand side you will see three dots ‘Show more tools & options’.
WordPress Search & Replace - Show More Tools & Options
WordPress Search & Replace – Show More Tools & Options
  1. Click on the ‘More tools & options’ (three dots) and select ‘Code Editor’ in the Editor section. This will allow you to edit the whole post or page all at once, rather than individual blocks (it shows the post or Page in the HTML format).
WordPress Search & Replace – The Code Editor
WordPress Global Search & Replace – Select the Code Editor

Copy the HTML to a Code Editor:

  1. Open your code editor and create a new blank document.
WordPress Global Search & Replace – Create a New Document in the Code Editor
  1. Select all the HTML text from your WordPress document (Ctrl+A) and copy it (Ctrl+C).
WordPress Global Search & Replace – Copy the HTML Text
  1. Paste (Ctrl+V) the copied HTML version of your WordPress Page or Post into your code editor.
WordPress Global Search & Replace – Paste the HTML Text in the Editor

Search and Replace (individually and globally) in the Code Editor:

  1. Open the code editor search and replace.
WordPress Global Search & Replace – Open the Code Editor Search & Replace
  1. Input the required search and replace text.
  2. Initiate the search and check the text found is what you want to replace.
  3. Select ‘Replace’ or ‘Replace all’ depending on your preference?
WordPress Global Search & Replace – In the Code Editor, Input the Search & Replace Text

Paste the Code Back into WordPress:

  1. When you’ve finished updating the document, select all (Ctrl+A) and copy the text (Ctrl+C).
WordPress Global Search & Replace – In the Code Editor, Copy the Updated Text
  1. Go back to the edited WordPress document and delete the original text.
WordPress Global Search & Replace – Delete the Original WordPress HTML Text
  1. Paste the updated text from the code editor back into the WordPress document.
WordPress Global Search & Replace – Paste the Updated HTML Text into the WordPress Document

Save (Update) and View the Page:

  1. Change back to the Visual Editor (if required).
WordPress Search & Replace – The Visual Editor
  1. And save the document.
WordPress Search & Replace – Update
  1. Don’t forget you can undo any changes…
  2. You can now view the updated document.

And that’s it. You have just completed a global search and replace…

Exit mobile version