Search & Replace – A Website Saving WordPress Script

Jan 4, 2013 by

This entry was written by , one of the OxonDigital members. The author's views below are entirely their own and may not reflect the views of OxonDigital.
Search & Replace – A Website Saving WordPress Script

Web Development is not normally something that I talk or blog about a lot here or anywhere to be honest, but I wanted to share with you a recent experience that I had with WordPress and more specifically the OxonDigital blog.

I am sure that some of you noticed recently that the feature images had disappeared! At first I thought it must of been user error, but after a long and thorough investigation I realised that it was a much bigger issue that I thought.

Great, just what I need! After a lengthy investigation I noticed that all the image files had changed, WTF! I hadn’t done this. So I went through every plugin, widget that we have on the OxonDigital blog and disabled, refreshed and checked. Nope, nothing.

Images now had an image path of:
img src="/home/danielbi/public_html/oxondigital.co.uk/wp-content/uploads/et_temp/Typography-98922_40x40.jpg"

That’s not right! It should be looking like this:
img src="/wp-content/uploads/et_temp/Typography-98922_40x40.jpg"

Pulling my hair out

Image Credit

At this point I was getting rather irritated, something had gone wrong and I wasn’t sure what it was. Those who know me well, will understand that this will of annoyed me no end! So after a number of days trying to figure out what was going on I put out some distress signals in the OxonDigtal LinkedIn group and spoke to a number of wordpress developers.

During some email conversations, Maria Robertson found and sent me a script that did a search and replace on the database. When I read the email, I must admit that I was very dubious of whether it would work. I mean I would need to mess around with an area that I wasn’t comfortable touching, I could lose the entire database and all the content that we have generated on OxonDigital. To say I was bricking it was an understatement.

After a few more days of trying different things, and researching the script that Maria had sent I finally took the plunge. I backed all my data up, if I was to lose everything I wanted a copy. I installed the script and went through the step-by-step process. Before I clicked the submit button, I thought for a good 5 minutes about whether I was doing the right thing, I hit the button. It was done, no turning back. After what I thought was an age, but more likely to be 0.00001 milliseconds the script had run and made ONE change. Yup, you read that right one change. After seeing that, I thought oh dear (being polite here) this hasn’t worked and I have probably lost all the content. I went to the front end and did a quick cache refresh and held my breath. On reload, I noticed that the image had re-appeared, I double checked a few more posts and pages before I continued to dance around the room, before being shouted at by the wife. Ok, that was a slight exaggeration but I was happy and relieved that I had fixed the issue and saved all the content.

Below is the step-by-step process that I took to restore the images on the OxonDigital website. I am sure that this script could be used for more that just fixing image issues and you can find out more here.

  1. Download Script Here
  2. Rename the script (replace.php) and upload it to your root folder
  3. Navigate to www.yourdomain.com/replace.php
  4. Now follow the step by step guide
  5. Include current file path and the new file path
    REPLACED /home/danielbi/public_html/oxondigital.co.uk/wp-content/
    WITH /wp-content/
  6. Then hit submit

That’s it, it was very easy if not a bit scary to use for the first time.

Have you ever used the search & replace script? Have you come across an issue that you couldn’t find the problem? How did you overcome an issue with your site that was driving you nuts? I would love to hear you experiences in the comments below and as always on twitter @danielbianchini

A digital marketer specialising in search marketing. As SEO Manager at SEOptimise, Daniel manages a large client portfolio and talented digital marketing team. As an SEO consultant Daniel has worked on high profile brands including National Express, Mothercare & Trafalgar. Follow Daniel on Twitter and Google Plus.

Share This

Tags

2 Comments

  1. Hi Dan, really glad it worked for you, its nail-biting stuff when you don’t do it every day, but what an excellent feeling when it does work, and great to see the images back up. I had to laugh at the bit where you said people that know me know this would drive me nuts, so true I can relate to that feeling. Thanks for sharing the experience. Maria

  2. Hi Maria,
    It was driving me nuts, and if it wasn’t for you I would of gone off my rocker. I am glad it is all fixed now, but I wanted to share the experience with everybody. Hopefully it will be useful for people in the future.
    Dan

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close