How to search and replace text and URLs across a whole website or blog

If you change your branding, company or product name, how do you change it throughout your website/blog? How do you change URLs, like http to https or even to a new site? Here is a guide.

There are many scenarios where you might want to change something in your blog or website or a client’s:

  • Companies or bloggers sometimes rebrand and give themselves, products or their blog a new name. The old name needs replacing throughout the website.
  • A website may be moved from one web host to another. It is possible to take the URL with you, but for various reasons you might want a fresh start with a new URL. Every link on the site in every post would need to be updated.
  • If you are changing from an http: website to an https: site you need to change all your internal links in posts so that they point to the new http: URL.
  • If you are developing a website for someone else, you build it on your own server, create a backup, then restore the backup on the customer’s site. You then replace all the old URLs with the new one.

How would you change text or URLs across a whole website? Sidebars and footers are not a problem and make a change in Appearance > Widgets and every page on the site is updated.

It is not easy with content in posts. Imagine how long it would take if the site had 100 or more pages? It could take a week to update all the posts with new branding, product names or URLs.

There is a quick way to change everything and just as there is a search and replace function in a word processor, there is also a search and replace in WordPress. It is not built in, but there is a plugin that can be installed to add the feature and it is a brilliant time saver.

Install Better Search Replace

Better Search Replace is a free WordPress plugin that adds, as you can guess from the name, a search and replace feature. It is exactly what is needed and it has 400,000 users and hundreds of 5-star ratings, which is always a good sign.

Installing Better Search Replace WordPress plugin

Here’s how to add it to WordPress:

  1. Go to Plugins
  2. Click Add New
  3. Enter Better Search Replace into the search box
  4. Click Install Now next to Better Search Replace
  5. Click Activate next to Better Search Replace

How to use Better Search Replace

Better Search Replace adds itself to a menu you probably have not used before. Go to Tools > Better Search Replace. The Settings tab can be ignored unless you have problems – it contains a slider that can be adjusted to make it more compatible with your setup. Most people will not need it.

The only tab you need is the Search/Replace tab.

At the top is Search for and below is Replace with and it could not be simpler. Enter the text or URL you want to find and enter the text or URL to replace it with. The case is important and if you search for New York, it won’t find new york.

Better Search Replace WordPress plugin
Select tables by Ctrl+clicking or Cmd+clicking.

The hardest part of using this plugin is selecting tables. WordPress stores information in multiple database tables and you must select the ones to use with search and replace. Here are the ones you most likely need:

  • wp_posts = Stores the text of every post on the site
  • wp_postmeta = Some plugins, like Yoast, store meta information
  • wp_comments = Stores post comments

Here is a comprehensive description of all the tables that WordPress uses. Other tables might exist on your site if you use certain plugins, so you might need to check the list and see if you can spot any.

Better Search Replace WordPress plugin

There is a Case-Insensitive checkbox that enables you to find words whether they are upper or lower case. Think about whether you want exact searches (the default) or whether you want to ignore upper and lower case (tick the checkbox).

Clear the dry run checkbox at the bottom and click Run Search/Replace.

Don’t forget to back up!

Nothing should go wrong, but why risk it? Make sure you back up your site before using the search and replace feature. UpdraftPlus Backups is a popular choice and there is a tutorial here: Don’t get caught without a backup of your WordPress website.