How To Do A Global Search And Replace In WordPress

Learn how to perform a global search and replace in WordPress without touching code.

How To Do A Global Search And Replace In WordPressWith WordPress, all of your content is stored inside a database (called a MySQL database or SQL file) on your server, not page files. This means that if you need to make global changes to your content like replacing text or URLs throughout your site, these changes have to be made inside your WordPress database tables.

Editing database tables, however, requires having knowledge of SQL. If you need to replace a string of text or links in your posts or pages, there are WordPress plugins that can help you save time by quickly searching either all fields and tables or specific areas of your WordPress database and then performing a global search and replace automatically.

In this tutorial, you will learn how to use plugins to easily perform a global search and replace in WordPress without touching code or editing your WordPress database tables.

How To Do A Global Search And Replace In WordPress

Being able to perform search and replaces quickly is important if you have many instances of text or links that need replacing, for example:

  • Changing a product/brand name or multiple product descriptions,
  • Replacing staff member names, telephone numbers, physical addresses, email addresses, etc.
  • Replacing misspelled words
  • Translating words
  • Changing internal/external website URLs
  • etc.

Imagine the following scenarios:

Let’s suppose that you run a community website promoting various local sports teams and events and one of these teams is known as the ‘Rainbow Bay Hawks.’
One day, the ‘Rainbow Bay Hawks’ decide to change their name to the ‘Rainbow Bay Eagles.’
Now you have hundreds of instances where the team’s old name appears in your content. You want to replace the old name with the new name. How can you make these changes without manually editing every instance on your site?

Also, let’s say that your WordPress site includes many published posts and pages containing images stored inside your WordPress media folder.

As your site grows and new posts and pages get added, you then decide to move all of your images and media to an external storage location (e.g. Amazon S3) to help improve your site’s efficiency and make your pages load faster to visitors …

Transferring images to other storage locations require replace image URLs on existing content

(Transferring images to other storage locations require replace image URLs on existing content)

This move changes the path (i.e. the destination URL) of your images, which requires changing the URLs of all the images that you have embedded into your posts and pages.

In most situations, it would be quite impractical to go through every post and page on your site and do a manual search and replace of all image links. Fortunately, if you are a non-tech-savvy WordPress user, plugins provide a simple solution you can use to search and replace content throughout your site without having to access your WordPress database.

Important Info

If you transfer images to a different image storage location without changing the URL of the images in your content, your posts and pages will continue displaying images stored in the old location (e.g. your WordPress images folder).

If you delete your images from the WordPress images folder or change image URLs before transferring images to the new location, your posts and pages will display “missing image” errors …

Incorrect image links lead to missing image errors

(Incorrect image links cause missing image errors)

When transferring images published on existing content to a different storage location, follow the steps shown in the order below to avoid errors:

  1. Add images to the new location
  2. Write down the destination path to the new images folder
  3. Perform a global search and replace to change the old path URL to the new destination using a search and replace plugin
  4. Delete images from the old folder or just ignore these.
  5. All of your image links will now point to the new storage location.

Search And Replace

WP Search & Replace plugin for WordPress

(Search & Replace – WordPress plugin)

Search & Replace is a free plugin that allows you to perform a simple search to find strings in your WordPress database and then replace that string.

You can search for content strings in areas of your database such as ID, post-content, GUID (Globally Unique Identifier), title, excerpt, meta-data, comments, comment-author, comment-e-mail, comment-url, tags/categories, categories-description, and many others. You can also use this plugin to replace the user-ID in all tables and the user-login for site security purposes.

Plugin Download

You can download the Search And Replace WordPress plugin here:

https://wordpress.org/plugins/search-and-replace/

Plugin Installation

To install Search And Replace, log into your WordPress admin, go to Plugins > Add New 

WP Plugins Menu - Add New

(WordPress Plugins Menu – Add New)

Type in “search-and-replace” in the Search field and click on Search Plugins

Add Plugins > Search And Replace

(Add Plugins > Search And Replace)

Locate the ‘Search & Replace’ plugin and click Install Now to install the plugin …

Install Search & Replace

(Install Search & Replace)

Activate the plugin after installation …

Activate the plugin

(Activate the plugin)

You can also activate your plugin by going to Plugins > Installed Plugins …

WP Plugins Menu - Installed Plugins

(Plugins – Installed Plugins)

This brings you to the ‘Plugins’ screen …

Plugins screen

(Plugins screen)

Locate the ‘Search & Replace’ plugin in the ‘Plugins’ screen and click Activate

Activate the plugin

(Activate the plugin)

The plugin will be activated and ready to use …

Search & Replace plugin is now active

(Search & Replace plugin is now active)

Plugin Usage

To access the plugin’s search and replace features, go to Tools > Search & Replace

Tools > Search & Replace

(Tools > Search & Replace)

This brings you to the ‘Search & Replace’ screen …

Search & Replace screen

(Search & Replace screen)

Using The Search & Replace Plugin

The Search & Replace plugin allows you to perform a number of useful functions, including:

  • Backing up your database
  • Replacing domain URLs
  • Importing MySQL databases

For the purposes of this tutorial, let’s focus on searching and replacing text strings.

Click on the ‘Search & Replace’ tab …

Search & Replace tab

(Search & Replace tab)

Here you can search for text or strings in all database tables, or just in specific tables, and perform global or specific search and replace operations …

Search & Replace fields

(Search & Replace fields)

Important Info

Backup your WordPress site before using this plugin! You cannot undo the changes made to your database by the plugin.

Using our previous example, let’s say that you want to replace all instances of the old link structure where images were being stored with links pointing to your new image folder location …

Let's replace all instances of this URL

(Let’s replace all instances of this URL)

First, make a backup of your WordPress database, then go to Tools > Search & Replace and do the following:

  1. Enter the URL to be replaced in the Search for: field (1)
  2. Enter the new URL into the Replaced with: field (2)
  3. Check Select all tables to find and replace strings in all of your database tables or select only the specific database tables to perform the search and replace function by clicking on individual table items (3)
  4. As a safety precaution, we recommend leaving the Dry Run box ticked. If you uncheck this box, the plugin will begin performing a search and replace as soon as you click the start button.
  5. Click on ‘Do Search & Replace’ to begin …

Search & Replace

Search & Replace

(Search & Replace)

The plugin will begin searching and replacing the strings in your WordPress database and let you know when the operation has been completed …

Search and replace results

(Search and replace results)

When performing a ‘dry run’, no changes will be made in your database. You can view the results by clicking on the ‘View details’ link …

Search & Replace - View details

(Search & Replace – View details)

To perform the changes, repeat the process, but change the following settings:

  • Make sure ‘Select all tables’ box is ticked
  • Deselect ‘Dry Run’ checkbox
  • Select the ‘Save changes to Database’ option in the ‘Export SQL file or write changes to DB?’ setting …

Use these settings to perform the actual search and replace

(Use these settings to perform the actual search and replace)

The plugin will perform the search and replace operation and save the changes to your database.

Search and replace operation completed

(Search and replace operation completed)

If you don’t want to save the changes to your database, you can export an SQL file with the changes instead (useful for developers) …

Making a search and replace to SQL file instead of your actual database

(Making a search and replace to SQL file instead of your actual database)

Once the operation has been completed, go back to your post or pages and check the results …

Global search and replace performed!

(Global search and replace performed!)

The old image links on all of your posts and pages have now been replaced.

For more information about this plugin, visit the plugin site here:

Alternative Search & Replace Plugins

In addition to the Search & Replace plugin described above, there are other search and replace plugins that you can use.

Better Search Replace

Better Search Replace - WordPress Plugin

(Better Search Replace Plugin For WordPress)

Better Search Replace consolidates and incorporates the best features from many search and replace plugins, incorporating the following features in one simple plugin, including:

  • The ability to select specific tables
  • The ability to run a “dry run” to see how many fields will be updated
  • No server requirements aside from a running installation of WordPress
  • WordPress Multisite support
  • A ‘PRO’ version with advanced/additional search and replace features

For more details, go here}:

Real-Time Find And Replace

Real-Time Find and Replace - WordPress Plugin

(Real-Time Find and Replace Plugin)

This plugin allows you to dynamically (i.e. at the time when a page is generated) replace code and text from themes and other plugins with code and text of your choosing before a page is delivered to a user’s browser. Because the find and replace happens in real-time no changes are needed to plugins or themes. A ‘PRO’ version is available with advanced/additional features.

For more details, go here}:

Text Replace

Text Replace

(Text Replace WordPress Plugin)

This plugin allows you to easily define text or HTML that should be used in your posts in place of words or phrases that are actually present in the posts. This is a handy technique for creating shortcuts or content ‘placeholders’ to common, lengthy, or frequently changing text/HTML, or for smilies.

For more details, go here}:

You can search for more search and replace plugins inside your WordPress dashboard (Plugins > Add New), or the WordPress Free Plugin Repository …

WordPress Plugins - Search and Replace

(WordPress Plugin Search – search and replace)

Search the WordPress Free Plugin Directory for search and replace plugins below:

Congratulations! Now you know how to do a global search and replace in WordPress without touching code or editing your WordPress database tables.

How To Do A Global Search And Replace In WordPress

(Source: Pixabay)

***

"I am beyond impressed with what you have put together. I can tell that you put a ton of hard work into building what you have. You have the absolute best content on WordPress I have ever seen!" - Robert T. Jillie

***

Originally published as How To Do A Global Search And Replace In WordPress.