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 in 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 different storage locations require replace image URLs on existing content)

This transfer 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 - WordPress global search and replace plugin

(Search & Replace WordPress global search and replace 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 

Plugins Menu - Add New

(Plugins – Add New)

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

Add Plugins > Search And Replace

(Add Plugins Menu > 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 …

Plugins - Installed Plugins

(Plugins Menu – 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’ page …

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)

Disclaimer

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 performed, 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 WP Plugin

(Better Search Replace WordPress Plugin)

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 WP Plugin

(Real-Time Find and Replace WordPress 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 Plugin

(Text Replace Plugin For WordPress)

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 Directory …

WordPress Plugin Search - 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)

***

"This is an awesome training series. I have a pretty good understanding of WordPress already, but this is helping me to move somewhere from intermediate to advanced user!" - Kim Lednum

***

Recommended Video Courses For WordPress Users

How To Set Up WordPress On LocalhostHow To Set Up WordPress On Localhost

Learn how to install, set up, and locally host a fully functioning WordPress site on your computer.

More info: How To Set Up WordPress On Localhost

Recommended Video Courses For WordPress Users

How To Optimize WordPressHow To Optimize WordPress

Learn how to optimize your WordPress site and improve your page loading speed.

More info: How To Optimize WordPress

Recommended Video Courses For WordPress Users

How To Back Up & Restore WordPress SitesHow To Back Up & Restore WordPress Sites

Learn how to safely and automatically backup your WordPress files and database and how to easily restore your WordPress site if something were to happen.

More info: How To Back Up & Restore WordPress Sites

Recommended Video Courses For WordPress Users

How To Use cPanelHow To Use cPanel

cPanel is a powerful and simple-to-use web hosting management software application that gives website owners the ability to quickly and easily manage their servers and websites using a simple and intuitive dashboard.

This video course will teach you how to use the main features of cPanel to manage your web hosting.

More info: How To Use cPanel

Recommended Video Courses For WordPress Users

Google ToolsGoogle Tools

This video course will help you learn the basics of using Google Tools like Google Analytics and Gmail.

More info: Google Tools

Recommended Video Courses For WordPress Users

Using Password ManagersUsing Password Managers

Password Managers provide an easy and secure way to keep track of all your passwords. This video course shows you how to use two FREE powerful password management tools.

More info: Using Password Managers

Recommended Video Courses For WordPress Users

How To Install, Set Up & Use WordPress MultisiteHow To Install, Set Up & Use WordPress Multisite

Learn how to quickly and securely set up an online community of websites or blogs using the powerful WordPress Multisite feature.

More info: WordPress Multisite

Recommended Video Courses For WordPress Users

WordPress SecurityWordPress Security

Learn how to keep your WordPress site or blog secure and protected from malware, hackers and brute-force attacks.

More info: WordPress Security

Recommended Video Courses For WordPress Users

How To Use FTPHow To Use FTP

This video course shows you how to use FTP (File Transfer Protocol) to transfer and upload files between your hard drive and your server using a free FTP program called Filezilla.

More info: How To Use FTP

Recommended Video Courses For WordPress Users

How To Use Amazon S3How To Use Amazon S3

Learn how to set up and use Amazon S3 to upload, store, manage, and protect your site’s images, large media files, downloadable files, stream videos and more.

More info: How To Use Amazon S3

Author: Martin Aranovitch

Martin Aranovitch is the founder of WPCompendium.org and the author of The Small Business Digital Manager. WPCompendium.org provides hundreds of FREE tutorials that show you how to use WordPress to grow your business online with no coding skills required! Get our FREE "101+ WordPress Tips, Tricks & Hacks For Non-Techies" e-course with loads of useful WordPress tips!

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