wesg header image 3

Wordpress Plugin: Find and Replacer

August 5th, 2008 · 35 Comments

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 <c></c> tags with <d></d> 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: <c>(*)</c>
Text to replace: <d>(*)</d>

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

Starting ID of page: page ID
Ending ID of page: page ID
Text to find: <e>(*)</e>
Text to replace: <g>(*)</g>

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.

<tag h>

TEXT TO REPLACE

</tag h>

To replace this, you must use the following query.

<tag h>

(*)

</tag h>

This kind of replacement won't work.

<tag h>(*)</tag h>

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

Category: Wordpress
Tags: , , , ,

Similar Posts

35 responses so far ↓

  • 1 United Voices // Aug 8, 2008 at 9:37 am

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

  • 2 Paul Stamatiou // Aug 13, 2008 at 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!

  • 3 wesg // Aug 13, 2008 at 9:33 pm

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

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

  • 4 SW // Aug 14, 2008 at 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.

  • 5 wesg // Aug 14, 2008 at 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?

  • 6 Thuy Lam // Aug 20, 2008 at 5:16 am

    Thanks for sharing.

  • 7 SW // Aug 20, 2008 at 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! :)

  • 8 wesg // Aug 20, 2008 at 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?

  • 9 baron // Sep 9, 2008 at 12:04 pm

    hi. Thanks for plugin

    perfect.

    Regards

  • 10 Boris // Sep 9, 2008 at 12:57 pm

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

  • 11 paulpop // Sep 22, 2008 at 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

  • 12 wesg // Sep 22, 2008 at 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.

  • 13 Haid Dasalami // Sep 24, 2008 at 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

  • 14 Haid Dasalami // Sep 24, 2008 at 2:45 pm

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

  • 15 wesg // Sep 24, 2008 at 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.

  • 16 Haid Dasalami // Sep 25, 2008 at 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

  • 17 Aaron Law // Sep 25, 2008 at 3:10 am

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

  • 18 Gene Steinberg // Sep 30, 2008 at 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

  • 19 wesg // Sep 30, 2008 at 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.

  • 20 Gene Steinberg // Sep 30, 2008 at 2:39 pm

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

    Peace,
    Gene

  • 21 Gene Steinberg // Sep 30, 2008 at 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

  • 22 wesg // Sep 30, 2008 at 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.

  • 23 Gene Steinberg // Sep 30, 2008 at 4:44 pm

    Oh. :(

    Any other alternatives?

    Peace,
    Gene

  • 24 wesg // Sep 30, 2008 at 5:07 pm

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

  • 25 Gene Steinberg // Sep 30, 2008 at 5:17 pm

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

    Peace,
    Gene

  • 26 Gene Steinberg // Oct 7, 2008 at 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

  • 27 Bryan // Nov 13, 2008 at 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.

  • 28 wesg // Nov 13, 2008 at 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?

  • 29 Bryan // Nov 13, 2008 at 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.

  • 30 Bryan // Nov 13, 2008 at 5:52 pm

    As it might make a difference:

    Wordpress 2.6.3
    PHP 5.2
    MySQL 5.0
    Character encoding UTF-8

  • 31 Robin // Jan 18, 2009 at 11:30 pm

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

  • 32 Fabio // Feb 27, 2009 at 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

  • 33 plienine // Oct 14, 2009 at 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?

  • 34 Sparanoid // Dec 8, 2009 at 8:19 am

    i just translated it into Chinese Simplified:

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

  • 35 criticalbiz // Jan 21, 2010 at 2:37 pm

    Super-useful plugin. Nice work.

Leave a Comment