Get the Best WordPress Backup
& Migration Plugin Today
Get Duplicator Now
Duplicator redesign announcement

[New] Introducing Duplicator’s Sleek Redesign: New Look, Same Great Features

We simplified backups and migrations with Duplicator's fresh new look. Dive into our redesigned interface, backup presets, helpful tooltips, and…
WordPress search and replace

The Art of the Swap: Creative Uses for WordPress Search and Replace 

Written By: author image Joella Dunn
author image Joella Dunn
Joella is a writer with years of experience in WordPress. At Duplicator, she specializes in site maintenance — from basic backups to large-scale migrations. Her ultimate goal is to make sure your WordPress website is safe and ready for growth.
     Reviewed By: John Turner
reviewer image John Turner
John Turner is the President of Duplicator. He has over 20+ years of business and development experience and his plugins have been downloaded over 25 million times.

Do you need to instantly update hundreds of links across your WordPress site?

The WordPress search and replace function can help. It’s a powerful tool that saves hours of manual work and potential headaches.

So whether you’re moving to a new domain or just need to update some outdated information, you’ll need to be familiar with search and replace. 

In this tutorial, I’ll explain everything you need to know about WordPress search and replace. From user-friendly plugins to advanced database queries, I’ve got you covered no matter your skill level.

Let’s get started!

Table of Contents

What is the WordPress Search and Replace Function?

WordPress search and replace is a way to find specific text or data in your website’s database and replace it with something else. 

Instead of just changing text in a single document, it can update information across your entire WordPress website in one go. This includes your posts, pages, comments, and other data.

Here’s how it works.

When you run a search and replace operation, WordPress scans through its database tables. It looks for the exact text or pattern you’ve specified.

Once found, it replaces that text with your new content. This happens at the database level, which means it’s thorough and fast.

Why is this so important? Well, imagine having to manually update hundreds of links or references scattered throughout your site. It would be time-consuming and prone to errors.

Search and replace automates this process, ensuring consistency and saving you valuable time.

Why You Might Need to Run a Search and Replace

Search and replace isn’t just a neat trick, it’s often necessary to maintain a healthy WordPress site.

The beauty of search and replace is its versatility — it can handle almost any bulk update you throw at it. Let’s talk about some common situations where you’ll find it helpful.

Changing Domain Names

If you’re moving to a new domain, you’ll need to update all your internal links and references. Search and replace can handle this in minutes instead of hours.

Updating URLs

Want to switch to a more secure connection for better SEO? You’ll need to update all your HTTP links to HTTPS. Once you search and replace URLs, you’ll have a smooth transition and avoid mixed content warnings.

Maybe you’ve restructured your site or an external resource you linked to has changed. Search and replace helps you fix these issues quickly.

Modifying Shortcodes

Changed a plugin that uses shortcodes? You might need to update these across your site to ensure everything still works as intended.

Updating Author Information or Other Metadata

If you need to change an author’s name or update categories site-wide, search and replace is your go-to solution.

Before Doing a Search and Replace

Before you perform a search and replace, there are some crucial steps you need to take. Think of this as your pre-flight checklist.

By taking these precautions, you’re setting yourself up for a smooth and successful search and replace operation. Remember, it’s always better to spend a little extra time on preparation than to rush into a potentially site-breaking situation.

Back Up Your Site

This is non-negotiable. A full backup ensures you can revert any changes if something goes wrong. I recommend using Duplicator for a comprehensive backup that’s easy to restore.

Duplicator Pro plugin

All you’ll need to do is create a new package. Feel free to customize the name and pick a cloud storage location.

Duplicator backup storage locations

Under Archive, choose All. This will save everything on your site in the backup file.

Duplicator full backup

Once you have a backup, you can restore it if the search and replace doesn’t go as expected. 

Understand the Risks

Search and replace operations can have unexpected consequences. A single typo could break your site. Always double-check your search and replace strings.

Test on a Staging Site First

If possible, try your search and replace on a staging copy of your site. This lets you catch any issues before they affect your live site.

If you don’t already have one, here are detailed instructions on building a staging site!

Be Specific With Your Search Terms

Broad searches can lead to unintended replacements. Be as specific as possible to minimize risks.

Some methods are case-sensitive, others aren’t. Know which you’re using to avoid mistakes.

Consider Serialized Data

WordPress stores some data in a serialized format. Not all search and replace methods can handle this correctly, which can lead to broken functionality.

How to Run a WordPress Search and Replace

Now that you’re prepared, let’s explore the different ways you can perform a search and replace in WordPress. We’ll start with the most user-friendly methods and work our way up to more advanced techniques.

Method 1. Use a Search and Replace Plugin

There are plenty of WordPress plugins that can perform a search and replace for you. They’re especially useful if you’re not comfortable diving into databases or code.

If you want to use a plugin, Search & Replace Everything is a good option. It can replace text and images. Plus, you can do dry runs before actually running the search & replace.

Search and Replace Everything plugin

All you’ll need to do is enter old text in the Search for box and the new text in the Replace with box. You can select all database tables to search and replace your entire website. Or, just choose specific tables you want changed.

Search and replace with a plugin

Then, preview the results. Search & Replace Everything shows exactly what text will be changed.

Preview search and replace

If everything looks right, run the search and replace. 

Alternative: Another popular search & replace tool is the Better Search Replace plugin. It supports WordPress multisite and has no server requirements.

Method 2. Update Your Domain During a Migration

One reason you’d need to search and replace text is after you’ve moved to a new domain name. With a migration plugin like Duplicator, you can update URLs during the migration.

Otherwise, you’d need to manually move all of your data to the new domain. Then, you’d have to install an extra plugin like Better Search Replace to remove all instances of your old domain in your database.

Duplicator can significantly speed up this process! Create a full backup of the old site and download its archive file.

Download archive zip file

Set up your new WordPress installation, buy a new domain, and activate Duplicator. Then, upload your backup to the Import page.

Import website archive

Click Continue. Then, launch the installer.

With the pro version, you can click on the Advanced tab. This gives you extra customization options like search and replace.

Advanced Duplicator migration

Validate the installation. Accept the terms and notices and continue to the next step.

Because you chose the advanced installation, you can choose which database tables to import.

Install WordPress database

Once the database is installed, you can make Duplicator run search/replace functions. In Step 3, enter the old text or URL in the Search field. Replace it with the new text.

Duplicator search and replace

Hit Next. Duplicator will automatically replace any of your outdated URLs or other data you want to replace. You’ll simply have to log back in to access your updated WordPress site.

Method 3. Use Your Web Host’s Search & Replace Tool

Some WordPress hosting providers offer their own search and replace tools as part of their managed WordPress services. This can be a convenient option if your host provides it.

Popular hosts that offer this feature include Kinsta, SiteGround, and WP Engine.

While the specific steps may vary depending on your host, here’s a general guide.

Log into your hosting account dashboard.

Look for a tool or section related to WordPress management or database operations.

Find the search and replace feature. It might be called “Search and Replace” or something similar.

Enter your search term and replacement text.

Select which tables you want to search in, if given the option.

If your host doesn’t offer this feature or you prefer more control, don’t worry. We have more methods coming up that might suit your needs better.

Method 4. Run a Search and Replace MySQL Query

For those comfortable with databases, running a MySQL query can be a powerful way to perform search and replace operations.

To get started, log into your web hosting account and open phpMyAdmin.

WordPress phpMyAdmin

Click on your database name. Then, hit the SQL tab.

phpMyAdmin SQL tab

Enter a SQL query with this format:

update TABLE_NAME set FIELD_NAME =
replace(FIELD_NAME, 'Text to find', 'text to replace with');

As an example, here’s the query you’d use to replace text in a blog post.

UPDATE wp_posts SET post_content = 
REPLACE(post_content, 'old-text', 'new-text');

This query updates the ‘post_content’ column in the ‘wp_posts’ table, replacing ‘old-text’ with ‘new-text’.

Remember to adjust the table name if your database uses a different prefix than ‘wp_’.

Click the Go button to run the search and replace.

This method is best suited for advanced users who need very specific changes and understand the structure of the WordPress database.

Method 5. Use the interconnect/it Search Replace PHP Script

Inter.connect has a free PHP script that you can use to run search and replace functions. This can be a good option for developers who don’t use the command line.

This method carries risks. One wrong move could seriously damage your database, so make sure you have a backup. Consider setting a recovery point with Duplicator just in case you get locked out of your WordPress admin dashboard.

To continue, download the script from inter.connect. Extract the file called Search-Replace-DB-Master. Rename it whatever you’d like.

Now, open your site’s files with an FTP client or file manager. Upload the folder to your root directory, usually called public_html.

Open a new browser window and search for the uploaded folder. It’ll look something like this: https://domain.com/search-replace-folder

Here, you’ll see a way to search and replace your database.

Interconnect.it search and replace

Enter your database details (you can find these in your wp-config.php file). Input your search and replace strings. You should also choose which tables to run the operation on.

Consider using the “dry run” option first to see what changes will be made. If everything looks good, run the actual search and replace.

Delete the script from your server once you’re done.

Method 6. Search and Replace with WP-CLI

For developers and advanced users, WP-CLI (WordPress Command Line Interface) offers a powerful and efficient way to perform search and replace operations.

WP-CLI is a command-line tool for managing WordPress. If you’re comfortable using a terminal, this method can be incredibly fast and flexible.

To use WP-CLI, you’ll need SSH (Secure Shell) access. This secure protocol is usually offered by your web host. To help you install WP-CLI, see this guide.

Here’s the basic command structure for a search and replace:

wp search-replace 'old-text' 'new-text' 

Options can help you add extra instructions. Here are some you could use:

--dry-run: Preview the search and replace before it runs.

--all-tables: Perform the search and replace on all database tables.

For more options, see the official WordPress documentation for search and replace with WP-CLI.

This method is ideal for developers managing multiple WordPress sites or for anyone comfortable with command-line operations. It’s particularly useful for batch processing or when you need to script your search and replace operations.

FAQs About WordPress Search and Replace

Can you search and replace in WordPress?

Yes, you can perform search and replace operations in WordPress. You could install a search and replace plugin like Better Search Replace or Search & Replace Everything. Manual approaches include running a SQL query or using WP-CLI.

How do I search and replace shortcodes in WordPress?

Replacing shortcodes follows the same process as replacing any other text, but requires extra caution. Use a method that handles serialized data correctly, like a specialized plugin. With Search & Replace Everything, enter the shortcode in the first box and the new shortcode to replace it.

Search and replace shortcodes

Conclusion

You can now perform search and replace functions like a pro developer!

While you’re here, I think you’ll like these extra WordPress guides:

Duplicator Pro simplifies the search and replace process during migrations. Before any search and replace, it can also create database backups. Try out Duplicator Pro today!

author avatar
Joella Dunn Content Writer
Joella is a writer with years of experience in WordPress. At Duplicator, she specializes in site maintenance — from basic backups to large-scale migrations. Her ultimate goal is to make sure your WordPress website is safe and ready for growth.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. We only recommend products that we believe will add value to our readers.