If you have a blog there will likely come a time when you need to change some block of text or PHP code that’s contained on every post and page.
A while back I enabled TLS encryption on this very blog, and one very important step in that process was changing all the URL references in the database from http:// to https:// to force WordPress to display the secure version of each post/page.
I could have made those changes manually but it would have been a long, drawn-out process and chances are I would have made a serious mistake along the way.
And as you probably know, ANY mistake can be serious when you’re dealing with your WordPress database.
Luckily, I found an easy way to quickly make that critical global change (plus a couple of other minor changes) on over 5,000 posts/pages in one fell swoop!
I thought it might be worthwhile to tell you about the awesome tool I used to make those “global” database changes. It really saved me a LOT of time, worry and frustration, and I think it’ll do the same for you.
As mentioned above, after I enabled TLS encryption on my blog I had to change all the references to the blog’s base URL in the WordPress database from http:// to https://.
In short, I had to add the letter s to the http part of the URL to change it to https.
I could have used the database tools provided in my blog’s CPANEL interface to manually alter those references in the WordPress database, but instead I chose to use an awesome plugin called Better Search Replace.
This plugin allowed me to change the URLs for every post and page (almost 3,000 of them) in just a few seconds.
Using Better Search Replace to make a global change to your database is easy. Just follow these steps:
1 – Back up your WordPress database. Do not skip this step because your blog could well be toast if something goes heywire during the procedure that follows. I repeat, BACK UP YOUR DATABASE before you do anything else!
The CPANEL interface for your domain should have a tool for quickly creating a backup of your database. If you can’t find it you can always contact your hosting company’s tech support folks and ask them to help.
2 – Click Plugins>Add New.
3 – Type better search replace into the search box, then install and activate the plugin.
Note: The plugin you’re looking for was written by Delicious Brains. It should be the first one on the page, but if it isn’t just scroll down the page until you find it.
4 – After the plugin has been installed and activated, click Tools>Better Search Replace to open it.
5 – Type the string of text or code you need to replace into the “Search for” field.
6 – Type the string of text or code you need to replace it with into the “Replace with” field.
7 – Select the database tables the change needs to be applied to. I only had to make changes to the wp_postmeta and wp_posts tables, but your blog might be different depending on the plugins you have installed.
If you’re unsure you can simply select all of the tables listed. Just be aware that the more tables you select the longer it’ll take for the search/replace procedure to finish.
8 – Double-check your selections to make sure they’re correct. If you make a mistake there’s no turning back because the changes made to the database will be irreversible and you’ll need to restore the database from a backup to fix any issues the changes might have caused. (You did back up your database, right?)
9 – Click the Run/Search Replace button to perform a dry run. (The Run as dry run? box should be checked by default.)
You should now see a short summary of the changes that will be made to the database. If everything looks as expected, continue on with the next step. If not, go back to step 5 and review your selections.
10 – Uncheck the box beside Run as dry run?.
11 – Click the Run Search/Replace button. The plugin will work its magic and make the requested changes to the WordPress database.
12 – Check your blog to make sure everything is working ok. If things look out of whack (or your blog won’t load at all) you can always restore the database from the backup you made in step 1 and start over.
Note: Don’t be afraid to enlist the help of your hosting company’s tech support personnel to help you complete the restore if you don’t feel comfortable doing it yourself. But that being said, it’s actually pretty easy to do using the “Restore Database” tool in CPANEL.
If your hosting company won’t help you (or if they want to charge you a small fortune), I recommend that you find a better hosting company. Most great hosts will help you with things like this for free.
Quick shameless plug: Awesome customer service and super-fast tech support are two of the reasons I host my blogs at inmotion Hosting (affiliate link).
That’s all there is to it. Now you know how to use the awesome Better Search Replace plugin to quickly make global changes to your blog’s WordPress database.
Bonus tip #1: This post discusses two easy ways to make your WordPress blog mobile friendly (and why you should do it).
Bonus tip #2: Want to make sure you never miss one of my tips? Click here to join my Rick’s Tech Tips Facebook Group!
If Facebook isn’t your cup of tea, I invite you to sign up for my Rick’s Daily Tips Daily Update Newsletter.
Want to ask Rick a tech question? Click here and send it in!
If you found this post useful, would you mind helping me out by sharing it? Just click one of the handy social media sharing buttons below.