When You Need And How To Mass Find And Replace In WordPress

Kumar Gauraw

Have you been in a situation when you updated your WordPress or one of your WordPress plugins which now requires you to do a global find and replace in many published posts on your blog?

Performing Global Find And Replace In Your WordPress Website

There are times when you are forced to think of an option to replace a particular word or a URL by a new one because may be you changed domains or because you needed to replace a hard coded affiliate link to a new link for any reason.

There are many such scenarios and I was in that situation just a few days ago when one of the plugins Shortcode Ultimate on my website came up with a new update that changed the name of the property “color” to “background”.

Now, I have used many shortcodes in many blog posts across hundreds of posts and I now need a way to do a global find and replace where I could find for the word “note color” to “note background”. It was frustrating when a plugin update caused this issue, but, to my serendipity, the task was easy. 

Similarly, when I decided to replace DISQUS by CommentLuv Premium on my blog, I realized I had links in each post that pointed to “disqus_thread”. I needed to change that to a different value after DISQUS was gone. Well, that also went well using the same method of global find and replace.

You will definitely need to perform a global find and replace when you are migrating a WordPress blog from one domain to another. When you change the domain, you need to replace every single reference to the old domain from your database with the new one. This feature comes very handy in such situations.

In this post, I am going to share with you three methods to get the job done. Based on your comfort level, you can choose the option that suits you the best.

Three Methods For Global Find And Replace In WordPress

There are three convenient ways to find a text and replace it with another across your entire WordPress website. Of course it only means a global find and replace in the MYSQL database tables behind your WordPress website or blog. I have tested all three of these methods and all of them do work like a charm.

Alright, now, let’s get into these methods right now!

[note background=”#DDDDDD”]Make sure you take a fresh backup of your MySQL database before performing any such search and replace operation using any of these three methods. Why? Because you want to be in a position to restore your database in case anything goes wrong in the process.[/note]

Method One – Search And Replace WordPress Plugin

Search And Replace is just another WordPress plugin that simply needs to be installed and activated and then it does, when it is asked to do, what it is supposed to do.

Once the plugin is installed, you can search in ID, post-content, GUID, title, excerpt, meta-data, comments, comment-author, comment-e-mail, comment-url, tags/categories and categories-description. It has a simple user interface from your WordPress admin area which can be accessed from Tools -> Search/Replace menu item.

Once invoked, the plugin presents you with the following screen where you can choose the tables you want to consider for the search/replace operation and then provide which word is supposed to be searched and what it is to be replaced with:

Search And Replace WordPress Plugin

 

Method Two – Global Search And Replace PHP Script

This is my favorite way of doing a global search and replace at a massive level without logging into WordPress area of my website. I also like this script because it doesn’t require me to add a plugin to my WordPress installation.

This is an external script file (basically, a simple PHP script) which you can download and place in your WordPress home directory. That means, this PHP file should be placed in the same directory where your wp-config.php file is located.

You can download the script from this location. The developers of this script maintain the latest version and provide helpful information on this page. Once the file is in place, you will invoke this script using your web browser with following URL syntax:

http://www.YourWebsiteDomain/ScriptFileName.php

The script will show you a screen where it will ask your permission to pre-populate your MySQL database information by reading your wp-config.php file. The screens looks like this:

Search and replace wordpress script screen step one

Make sure the checkbox is selected and press the submit button. Now, it will bring a screen where you will be asked which tables you want to include in this operation. You can choose ALL tables or you can choose only wp_posts if you have to only replace something within your post contents. Choose the tables and continue.

Finally, it will ask you for search text and the new text that will replace your search text. Provide that information and submit. The script will search and replace all occurrences of the searched term with the new term across all the tables you selected for this operation.

The script will provide you with the status message showing how many occurrences were replaced. And then, you are done!

Method Three – Search And Update MYSQL Table Using phpMyAdmin

To perform a global search and replace using this method, you need to have access to your cPanel account. If you are ready, log into cPanel and start your phpMyAdmin from there.

When you are inside phpMyAdmin, select your MySQL database table of interest and then perform a SQL update statement.

For example, I wanted to replace the word “#disqus_thread” with “#respond” in every blog post. All I did was, went to the table “wp_posts” using phpMyAdmin  and opened the SQL tab to execute following SQL update statement:

Update WP Posts Using phpMyAdmin For Global Find And Replace In WordPress

After writing the query all I had to do was hit the “GO” button on the screen to execute the query and the job was done!

Simple and easy. Know which table (for blog posts, your table will always be wp_posts and the field which stores the blog post is “post_content” as shown in the image above) and write your find and replace query which is actually an UPDATE statement as shown above.  Execute the query and you are done!

Do You Have Any Questions/Suggestions?

If you have any questions about any of these methods, please ask in the comments section and I promise, I will respond to you.

If you know another method which can be as useful as any of these, please use the comment section to share your suggestions and add value to this post.

Thank you kindly!

Kumar Gauraw

Posts Twitter Facebook

Kumar Gauraw is a Personal Branding & Social Media strategist helping entrepreneurs and skilled professionals achieve personal and professional success by developing leadership and leveraging the power of the Internet, Blogging and Social Media.

13 Awesome Thoughts So Far, Add Yours Now...

  1. Shweta Sharma

    Hi Kumar,
    The script (method 2) is so powerful. I was going through their page through your link and just found out that it also works with any other CMS as well which uses MySQL. That means it will work even with Joomla. This is powerful script.
    The only thing we need to be careful about is, remove the script from the server when work is done so it can’t call accidental damage.
    Your post as very resourceful as always. Thank you sir!

  2. Yes indeed Shweta. I like the script method as well. It’s kind of neat and totally independent.
    Well, yes, the script does work with any MySQL database. So, it should virtually work everywhere.Thanks for taking time to lave your feedback with us here.
    Regards,
    Kumar

  3. Gosh Kumar, I sure hope I never need that. I migrated one blog to another about three years ago but didn’t really have to change any of the internal links. My hosting service at that time helped me with all of that so what else was needed I couldn’t tell you right now since it’s been so long ago.

    This actually looks kind of confusing to me but I would think if I really had to do this then going through the process and following along with what you’ve shared would make it a lot easier for me. I’m a hands on kind of person so I prefer to just jump on in and try it out.

    Let me just say that I hope I’ll never need to! lol…

    Thanks again and enjoy your weekend. I’m going to read your other post to you sent me.

    ~Adrienne

    • Hi Adrienne,
      Thank you for taking time to leave your thoughts on this and I am happy for you that you didn’t need it so far.

      However, I have needed it since I moved out of DISQUS commenting system to COMMENTLUV and since I place a link in my post for people to click to go to put their comments, that link works differently when you are with DISQUS. I needed to change that to work in accordance with CommentLuv and then, I needed to perform this operation ๐Ÿ™‚

      And you don’t need to do a global search and replace when you move your website from one host to another. That is straight forward process. However, when you move your website which is known as DomainA and then you transfer the same content under a new name, say DomainB, you’ve a problem and you will may need to do something like this ๐Ÿ™‚

      So, in situations like that, these tools are pretty handy and since I am a person who does a lot of website development, migration and SEO work for many clients, I needed to document it for myself and what better way than placing it on my own blog to help myself and everybody else! So, here I am with this post.

      But then, I also really really wish you never have to do this for yourself ๐Ÿ™‚

      Regards,
      Kumar

  4. Wow Kumar, quite the tools here. I haven’t needed to do it yet but this is something to keep because you never know when you may need it for your blog. I had such a struggle going from Blogger to WordPress that I would not recommend that one to anyone. I would start from scratch if I knew then what I know now. Thanks for sharing this informative piece.

    • Hello Lisa, Thank you for dropping by. You are right. It is better to dig the well before we feel thirsty.

      And yes, I can completely understand the pain of moving from blogger because I used to be there as well. I had a small blog and so migrating wasn’t that difficult. However, if you have a lot of things to migrate from blogger to WordPress, it is quiet a task. Did you take professional help in your migration? Or did you do it yourself?

  5. Hi Kumar,

    I have used the Search And Replace plugin before it makes it very easy to do this. Another method that I have used in the past is to export the database and then use the search and replace feature in notepad++.

    That method can definitely take a while, especially if you have never done it before. Your methods definitely sound like they can save some time.

    If I ever need to do this for one of my sites, I will try out one of the other methods that you talk about. Thanks for sharing, I know that they will definitely help anyone who is looking for this info.

    I hope you have a great weekend.

    • Hi Susan, Wow! I didn’t think that that approach. I think exporting into notepad and then doing find a replace is another way of getting the job done. Time consuming but safe. Works! Thank you!

      Anyone who has plugins, may need to get some help in this area since plugins keep coming with new versions and sometimes a complete redesign (like Shortcode Ultimate I mentioned about) and in such cases, we do need to do this acvitity the way I needed to do recently.

      Thank you for dropping by and sharing your thoughts.

  6. Hi Kumar,
    Due largely to your kindness, I have not need of these.
    If, at any time, I have need, at least I know where to look for some awesome tips, tools and techniques.

    Have a glorious weekend!
    Bill

    • Awesome Bill. We complement each other ๐Ÿ™‚ Thank you for helping out with things I need your help with.

      Just came back from a RedBull festival, burnt a few calories and now back to internet marketing ๐Ÿ™‚ You have a great weekend too!

      Regards,

      Kumar

  7. Great tips. These will prove to be a life saver next time if I needed to do bulk find and replace in WordPress!

    Thanks, Kumar for the sharing. ๐Ÿ™‚

    • Hi Jasmine, Thanks for dropping by and leaving your feedback. I’m glad you found it useful. Have a wonderful weekend!

  8. Hi, that’s very useful tips on wordpress. I’m a regular user of wordpress. This is going to be really helpful for me…

Please Note: My goal is to host interesting conversations with caring, honest, and respectful people. Therefore, I reserve the right to delete comments that are snarky, offensive, or off-topic.