WordPress Plugin: Find and Replacer

Please be aware that this plugin was built quite some time ago and I haven’t had a chance to update it in some time. It may work properly, it might not. Make sure you have a database backup before using.

Blogs often live online for many years. The problem is that the blog often changes its look or code base, and must update all the earlier posts.

That’s where my newest plugin comes in; Find and Replacer enables you to find and replace single words or phrases, and even entire tags. This means that within seconds you can replace all the early tags in your blog database with the newer ones.

Sure there are other WordPress search and replace plugins out there, but none offer the level of power that Find and Replacer does.

It has been tested up to the latest version of WordPress, 2.7. Due to the nature and unique properties of many blogs, please let me know if your find request does not work properly. If you have problems with an earlier version, or even if it works properly, please contact me or post a comment.

Translations

The next version of Find and Replacer is compatible with WordPress’ locale system. If you are interested in translating for your locale, please comment below or use the contact form and I will send you the required .PO file for you to translate.

Current translations

Thank you to all those who have offered to translate!

Donations

If you wish to donate to further the development of this plugin, please use the PayPal button below. Comments on posts are also very valuable to me.




Limitations

  • Processor-intensive when checking a large quantity of pages.
  • Search is case-sensitive.
  • Whitespace must be similar.
  • International characters must match those stored in the database.

Latest changes

Version 1.5 brings a number of advanced changes to the plugin. In addition to improved search behavior, users can now search through comments and make replacements there. Revision interaction has also changed. Database records are no longer overwritten regardless of post status — you can skip revisions and only make changes to displayed posts.

It is highly recommended that you keep revisions enabled and use the default revision behavior. This way, should the plugin make a change you don’t like, you can return to an earlier state.

Usage

  • After activating the plugin, navigate to the admin panel interface, where the options can be entered to edit the required number of pages or posts.
  • View the page list at the bottom, and enter the correct attributes for replacing your text.

Examples

To replace Hello world with Goodbye world enter the following.

Starting ID of page: page ID
Ending ID of page: page ID
Text to find: Hello
Text to replace: Goodbye

To replace tags with tags and leave the inside text alone, enter the following.

Starting ID of page: page ID
Ending ID of page: page ID
Text to find: (*)
Text to replace: (*)

The plugin now has the ability to replace tags when they surround other tags. For example, to change Text to Text, do a normal tag query.

Starting ID of page: page ID
Ending ID of page: page ID
Text to find: (*)
Text to replace: (*)

To modify only a single page, enter that page's ID in both the first and last ID field.

Starting ID of page: 100
Ending ID of page: 100

After receiving a comment about replacing text with whitespace, I've added an example. Currently to replace text with whitespace you must make your find text include whitespace.

TEXT TO REPLACE

To replace this, you must use the following query.

(*)

This kind of replacement won't work.


(*)

I'm working on a solution and hope to include it in a later version.

Caution: This plugin is extremely powerful. A slip of the mouse can cause your blog to edit many phrases that you wished were left alone. Be sure to read the options carefully.

Download latest version of Find and Replacer

Installation

  1. Copy the folder find-and-replacer into your WordPress plugins directory (wp-content/plugins).
  2. Open the WordPress Admin Panel and activate the plugin.
  3. Navigate to the Admin Panel for Find and Replacer, where you can edit all the pages you desire.

FAQ

What is the purpose of this plugin?
With blogs growing larger and larger all the time, Find and Replacer makes it super easy to edit pages throughout your blog installation. Change everything from words and phrases to complete tags.

What options are available?
In the interface panel, you have the ability to fine tune the editing process. You can:

  • enter the starting and ending page IDs of posts you want to modify
  • select the entire post database
  • choose between editing the post content, title, or both
  • view page IDs and other data for your posts

How does it all work?
Find and Replacer uses the REGEX engine, or regular expressions. This is a powerful system built into PHP for finding and replacing text when only specific data is known. This is the only way to replace entire tags in one pass.

Can I change tags surrounding tags?
Fixed in version 1.1, FAR can now modify tags when tags are inside. It does this by breaking the request into two queries. For more examples please visit the examples section.

Can I replace text over multiple lines?
Yes. If you are replacing text with multiple lines and you want to preserve text inside it, you just need to put the placeholder (*) in the correct spot. A fix is upcoming, but until then have a look at the examples.

How does FAR work with revisions?
As of v1.5, Find and Replacer changes the way it interacts with revisions. Previously it edited each entry in the database as if it were the same. Now, you have the option to skip revisions. This means that if your search does not go the way you want, you can return to a previous revision with no issue.

Can I modify comments?
In v1.5, yes.

Screenshot

Click for a larger view.

Click for a larger view.

Changelog

v1.0 –– August 5, 2008
* Initial release

v1.1 -- August 9, 2008
* added ability to change tags surrounding tags

v1.2 -- August 20, 2008
* made replacements compatible with PHP 4
* updated readme about whitespace

v1.3 -- September 9, 2008
* brought up to WordPress translation standards
* includes French translation

v1.3.1 -- September 11, 2008
* displays other languages properly

v.1.4 -- September 12, 2008
* updated replacement algorithm
* displays the post type

v1.4.1 -- September 24, 2008
* prevents blank posts or pages from being written to the database

v1.5 -- October 6, 2008
* lowered number of database queries required
* improved search algorithm
* added ability to search comments
* added ability to skip revisions
* made search more accurate when replacing entire post
* improved accuracy of replacements not requiring REGEX

v1.6 -- January 6, 2009
* Added WordPress 2.7 compatibility

View all plugins

[tags]Wordpress, blog, plugin, automate[/tags]


{ 51 comments… add one }

  • United Voices August 8, 2008, 9:37 am

    thanks for this simple software. it’s made my job much more easier. cheers

  • Paul Stamatiou August 13, 2008, 9:12 pm

    I don’t yet have a use for this but I think I will as I change around some of my tags. Thanks!

  • wesg August 13, 2008, 9:33 pm

    @Paul Stamatiou
    Thanks, Paul. Have a look at my other plugins!

    http://www.wesg.ca/wordpress-plugins/

  • SW August 14, 2008, 4:52 am

    I LOVE this plugin and have used it on some small find/replace tasks. I am not a great database person, so using sql code is difficult for me, so this plugin EASILY fixes my problems :)

    However I have one problem I’m trying to fix: some of the data I want to find/replace is on multiple lines and there is a varying degree of white space between some of the code in different tables.

    A great modification to make this even more powerful would be to search for multiple lines of text and then to also ignore white space.

  • wesg August 14, 2008, 6:42 am

    @SW
    Thanks a lot, I really appreciate it! I will certainly look into that for the next version.

    Do you have any example text?

  • Thuy Lam August 20, 2008, 5:16 am

    Thanks for sharing.

  • SW August 20, 2008, 8:55 am

    @wesg: sorry for my delay :)

    Ok, for example in my posts I copy/paste form Dreamweaver HTML code. I have other plugins on my blog that allow me to perfectly render that HTML within the posts, but sometimes I need to go back through a few dozen posts to change the code.

    For example here is some code I want to find:

    height=”5″>

    <table width=”155″ border=”2″ cellpadding=”5″ cellspacing=”2″

    So you see? Because there are multiple lines, plus white space between the content, it’s not possible to do big chunks like this at one time.

    Hope that helps! :)

  • wesg August 20, 2008, 6:01 pm

    @SW: I had a look at your text and was able to make changes. I assume you have text between the two tags you have provided and wish to leave that alone. There is a small issue with whitespace, and I’ve added a new example to the page.

    When I tested your code and searched for it, I could find the tags you provided. Is that what you were looking for?

  • baron September 9, 2008, 12:04 pm

    hi. Thanks for plugin

    perfect.

    Regards

  • Boris September 9, 2008, 12:57 pm

    Hello
    Thank you very much Wes. Thank you for the link

  • paulpop September 22, 2008, 7:31 am

    I tried to use your plugin to make a text change to my posts. Every post and title with that character combination was erased, all text not just the one i wanted to change.

    I’m running wp 2.3.3
    Is there some limitation to what kinds of characters can be changed?
    I tried to use this as a simple charset mismatch fix

  • wesg September 22, 2008, 7:13 pm

    @paulpop: Find and Replacer v1.4 escapes characters that could break the database code, as some text can conflict with the algorithm that does the finding.

    If you could, please use the contact form to send me some example text and I will work on a fix.

  • Haid Dasalami September 24, 2008, 2:44 pm

    How would you find double spaces between words–that is, not after periods? If the plugin could do that, I’d definitely want to use it. I’m always mortified when I read an older post and then discover I have double spaces all over the place–like this, for example.

    Regards,

    HAID

  • Haid Dasalami September 24, 2008, 2:45 pm

    LOL. Your theme purified my example, but you get the idea.

  • wesg September 24, 2008, 3:19 pm

    @Haid Dasalami: What exactly do you mean with my theme? :) I’ll look into a way to replace double spaces that don’t happen after periods and try to add it to the next version.

  • Haid Dasalami September 25, 2008, 12:38 am

    That would be great and much appreciated. By the way, the converse would also be desirable, for those of us who format the old-fashioned typewriter way: that is, it would be nice to be able to find all the SINGLE spaces after periods as well. I suspect there are more than a few blog authors who’d kill for such a tool. (Considering my niche, maybe I should rephrase that). ;)

    One other thing. Is it necessary to set up the “find” with the “replace” string? Is it possible just to find the text string and then decide whether or not to replace it?

    I suppose I ask too much, but I AM thinking of a couple nice uses for this plugin. One thing is that Islamic transliterations are often spelled in various ways. I try to be consistent with my preferred spellings, but I don’t always succeed, and I really don’t want to change another writer’s spelling choice when I quote them, for one thing. That’s just one example.

    Anyway, I’ll be watching for developments, and when I get a chance I’ll be testing the plugin as it stands now.

    Best regards,

    HAID

  • Aaron Law September 25, 2008, 3:10 am

    Oh my god! That’s what I want since I’ve been a blogger in 2002!

  • Gene Steinberg September 30, 2008, 1:23 pm

    How about a wild card search/replace feature?

    What I mean for example

    Take: title 999 replace

    Search: title ???? replace
    Replace: title replace

    In order words: the numbers or text indicated by a question mark may be different from string to string, but that would allow me to eliminate all of them.

    Make sense?

    Or do you already have this capability somehow?

    Peace,
    Gene Steinberg

  • wesg September 30, 2008, 2:24 pm

    @Gene Steinberg: this functionality is built into the plugin already. By using (*) in place of the ???? you can make replacements without knowing the value of the actual text. Currently the limitation that I just noticed is that if you happen to have more than 1 title ??? replace in the post, it will replace the entire post. I’ll have to work on that.

  • Gene Steinberg September 30, 2008, 2:39 pm

    Oh, great. That may be just the ticket. :)

    Peace,
    Gene

  • Gene Steinberg September 30, 2008, 2:58 pm

    Tried. Isn’t working.

    I’m trying to replace, for example:

    [quote comment="12814"] and turn it into [quote]

    So I’d use one (*) for each wildcard character or for all characters?

    I’m searching in Comments.

    Isn’t working.

    What am I missing?

    Peace,
    Gene

  • wesg September 30, 2008, 3:27 pm

    @Gene Steinberg: One wildcard is required, so in your case I was able to turn [quote comment="12814"] into [quote] by using the find string of [quote comment="(*)"].

    You say you’re searching in comments, but currently FAR doesn’t search through them. It is limited to titles and post content.

  • Gene Steinberg September 30, 2008, 4:44 pm

    Oh. :(

    Any other alternatives?

    Peace,
    Gene

  • wesg September 30, 2008, 5:07 pm

    @Gene Steinberg: stay updated with the plugin, and I will try to add this feature in the coming days.

  • Gene Steinberg September 30, 2008, 5:17 pm

    Thanks. I’ll try to check back here every so often. :)

    Peace,
    Gene

  • Gene Steinberg October 7, 2008, 12:15 pm

    Your new version was partly successful. I was able to remove the wild cards in comments, but when I tried a straight search/replace of regular text to correct to blockquotes, it replaced everything in the blog instead and I had to restore from my backup. Not a great loss, because I was able to restore to something posted only a couple of hours earlier. But I am concerned about this.

    On the positive side of the ledger, it allowed me to switch from Quoter, no longer being developed, to WP Threaded Comments.

    Peace,
    Gene

  • Bryan November 13, 2008, 2:16 pm

    Is something special required when dealing with slashes [/]?

    I’m attempting to replace the location of graphics files after a ISP change.

    Example: /home.earthlink.net/~bldumka/

    replaced with: /www.dumka.us/

    The code responds with a warning about mismatched number of parameters and nothing is changed.

  • wesg November 13, 2008, 3:54 pm

    @Bryan:
    I had a look at the plugin and tested it with your text, and it replaced properly. I searched for /home.earthlink.net/~bldumka/ and replaced it with /www.dumka.us/ without issues. I even tried it inside an image tag in a post with lots of text, and it worked as expected.

    Could you copy and paste the exact code that was printed to the screen?

  • Bryan November 13, 2008, 4:31 pm

    The following lines were repeated dozens of times:

    Warning: Wrong parameter count for str_replace() in /f1/content/whynow/public/wp-content/plugins/find-and-replacer/find-and-replacer.php on line 165

    Warning: Wrong parameter count for str_replace() in /f1/content/whynow/public/wp-content/plugins/find-and-replacer/find-and-replacer.php on line 198

    Warning: Wrong parameter count for preg_replace() in /f1/content/whynow/public/wp-content/plugins/find-and-replacer/find-and-replacer.php on line 199

    and the final message was:

    No changes were made because some posts were empty.

  • Bryan November 13, 2008, 5:52 pm

    As it might make a difference:

    Wordpress 2.6.3
    PHP 5.2
    MySQL 5.0
    Character encoding UTF-8

  • Robin January 18, 2009, 11:30 pm

    Works beautifully, but doesn’t make changes to the excerpts — is that a possible future upgrade?

  • Fabio February 27, 2009, 4:14 pm

    Don’t works on Wordpress 2.7.1?
    Warning: Wrong parameter count for str_replace() in /home/central3/public_html/tubepornobr.com/wp-content/plugins/find-and-replacer/find-and-replacer.php on line 168

    Warning: Wrong parameter count for str_replace() in /home/central3/public_html/tubepornobr.com/wp-content/plugins/find-and-replacer/find-and-replacer.php on line 203

    Warning: Wrong parameter count for preg_replace() in /home/central3/public_html/tubepornobr.com/wp-content/plugins/find-and-replacer/find-and-replacer.php on line 204

  • plienine October 14, 2009, 1:30 pm

    Hello,
    I am searching how to mass remove links?
    For example:
    I have links which I do not know, and want to reaplace all them.
    I tryied to find a href, but it only remove a href, but left link as text.

    What suggestions?

  • Sparanoid December 8, 2009, 8:19 am

    i just translated it into Chinese Simplified:

    http://lib.sparanoid.com/i18n/wp/find-and-replacer/

  • criticalbiz January 21, 2010, 2:37 pm

    Super-useful plugin. Nice work.

  • Irvine Babysitter April 6, 2010, 11:15 am

    Hi. I just installed this plug-in, activated it, navigated to the Edit Posts page but don’t see any option for entering search terms. The Edit Posts pages looks exactly as it always has. Did I miss something? BTW I’m using WP Version 2.9.2

  • Ricardo April 28, 2010, 6:49 am

    Is it possible to make it automatic? Means.. everytime x keyword is posted it goes replaced by one else??
    How?
    Thanks

  • Akin May 19, 2010, 7:22 pm

    You are a GOD! (send) :)

  • Gary September 8, 2010, 6:02 pm

    Has anyone tested this plugin with version 3.0.1?

  • Dean November 6, 2010, 9:26 pm

    Yeah this is one of the most powerful plugins I can think of and yes it’s great.

    I just wanted to know though if it was possible to streamline it a bit more instead of replacing word by word.

    For example:

    words to find:
    top
    finest
    greatest
    unsurpassed
    optimum

    replace with:
    Best

    It would be even better if it allowed multiple word change queries in one go for example (where X is the the words to find and Y is the words to replace with:

    1X Find words:
    hop
    jump
    skip

    1Y
    running

    2X find words:
    running
    chasing after
    crawling

    2Y replace with:
    walking towards

    where the numbers 1, 2, 3, 4, … etc hasn’t got a limit. That way we can replace multiple words or phrases all in one click of a button (we’d be able to store and save this list by copying and pasting etc and just building on it.

    I hope you understand what I mean, even if it can’t be done, this tool is probably the most frequent tool I use.

    Thanks heaps.

  • wesg November 7, 2010, 12:35 am

    @Dean: Thanks so much for the comment and excellent feature request. I hope to fit in some plugin upgrades in the near future, and I’ll definitely take your idea into consideration when I make the improvements.

  • Brad December 12, 2010, 5:17 pm

    Well, I’ve used this before with success… however, today I used it to remove a tag from a previous theme which appeared on nearly every page… it was [separator] … well, it made every word on every page completely screwed up. So bad that i had to just recover/restore from last night’s back up which cost me an entire day’s work.

  • sui January 21, 2011, 6:31 pm

    yeah, it works fine sometimes but it creates serious problems other times… like with a large number of posts, random letters were replaced with nothing! :< please help.

  • Ricky Price January 28, 2011, 6:29 pm

    Your plugin is exactly what I had been looking for. You can’t imagine the amount of work hours you have saved me. I would like to help you with the Spanish translation if you like.

  • jflycn February 14, 2011, 5:21 pm

    OMG. The program removed all the “\” from my posts. All the latex equations were screwed. There are hundreds of them. If the author read this, please please email me how to save my posts. :(

  • wesg February 15, 2011, 10:31 am

    @jflycn: I’m sorry the plugin did that to your posts. I built the plugin some time ago, and couldn’t test against all the possible scenarios. I hope to have a new version out some time that can better handle complex replacements, and perhaps add revisions instead of overwriting everything. Hopefully you have a database backup that you can restore to. If not, I’ve been able to rebuild my database using the Google cache.

  • Sven April 1, 2011, 9:49 am

    @ wesg

    This is a very usefull plugin, I hope that you some day find time to upgrade it to WP 3.1 (3.2 comming up soon).

    Thank you for sharing your knowledge!

  • Mike Carter May 17, 2011, 1:47 am

    Hi — yes, this plugin is IT! And I want to throw in my two cents with Dean, above (below?). Multiple replacements is definitely needed. I use this to get rid of those code-destroying curly quotes. To be able to do both the left and right at once and replace with ‘ would be very handy. And, again, like the add quick tag plug in, export and import settings.

    Good job!!!

  • Smartnickhere July 14, 2011, 4:44 am

    can i set an auto find and replace function?

    please let me know if there are any option available like this…

    smartnickhere@gmail.com

  • Moviesnowx August 12, 2011, 1:06 am

    How

Leave a Comment

Next Post:

Previous Post:

Twitter Feed