March 12, 2010
This little plugin is always in my toolbox of “I don’t want to live without this” plugin. I don’t use it often but when I do it is a dragon slayer. Let me give you a couple of examples where this little tool shines and shows it’s stuff. Search and Replace.
You are moving your blog from one domain to another. Not too hard, right? You do the backups the re-installs of the files, restore the database, change the domain name in the general settings and up pops the blog. Cool. Everything look like it is good and you take down the old site. Suddenly all the images disappear from your posts. Why? Because the image url’s were still pointed to the old domain name. They worked fine linking back to their original location till you took down the site. What do you do?
Did you move the image files to the new site? (Probably, let’s hope so) You thought they were the ones being pulled into the new location. But when you open a post in the editor, there is the link back to the old domain wp-content/upload etc. Now the light comes on. “Holy Kow, I have to change all the image links in all the posts to point to the new domain.
Senario 2
You built a new site “Off site” for a client. Once they are happy with the way it looks you move all the files to their hosting, point the blog to their domain name and . . . Same as above. All the image links in the post/pages are back to your Development site. What do you do now?
The answer is the same. Use the plugin search and replace. It will go through the database searching for the string to the old domain and replacing it with the new domain. The plugin has the option to only search and replace in certain areas of the database. Only need something in a post or page replaced? check “content”.
For example: You need to replace www.myolddomain.com with www.mynewdomain.com. Go to the search and replace settings page. Select “Content” then enter www.myolddomain.com in the search field and www.mynewdomain.com in the replace field. Click “GO” and in about 1/10th of a second it is done.
Note: Make a backup of your database before using search and replace.
This past week I had a friend who set up a new site for a client. The client had been writing all the content for the site in Word. When the project was ready for content the client did a copy and paste move of all the content to the new pages for the site.
The content was all there, but the site was supposed to be justified so all the margins lined up right and left. That’s how the Style.css was setup for the site. The pages however were ragged right. What happened? Looking at the HTML editor revealed that every single paragraph for all the pages and post started with <p style text-align=”left”> That line of html overrode the style.css. My friend thought it was going to take going through the posts one at a time and removing the formatting code from each paragraph.
Enter search and replace. Search: <p style text-align=”left”> Replace: <p> . Five seconds later the entire site was “justified” and hours of tedious hand editing was avoided.
Don’t leave this tool laying around. Meaning, either don’t let anyone using the site know it exists, or better yet, when you are done using it, “DELETE IT” from the site.
Why? because this can be a very dangerous tool. If you are not careful you can end up changing text strings that you don’t want changed.
In the example above on domain name change. If you have a post that references your old domain name and you spell it out www.yourolddomain.com; when the search and replace runs it will replace that string with the new one. Therefore, you think carefully about the string you want to search and replace. In this example you could go further by searching for www.yourolddomain.com/wp-content/uploads/ and replace it with www.yournewdomain.com/wp-content/uploads/ This would prevent you changing any reference to just the old domain itself.
If someone sees this plugin and decides to use it for a quick way to change references or fix typo’s in a post, they could end up taking down the entire blog.
That is why it is good to only have it available on sites where no one can “stumbleupon” the plugin settings and try and use it. I treat it like a powertool. It works great, gets the job done fast, but shouldn’t be left where the “kids” might find it.
Filed under Plug-ins