Last night I copied a line of code into the WordPress editor, hit “Update” and *POOF* Everything bellow the line of code I just copied disappeared! What the F*%&?!
If before you knew of someone who heard about someone who erased some code… now you know that someone: me. Here’s my story.
I take a look at the screen, I don’t see the code. I stand up and take a couple of steps back; perhaps I’m reading something wrong? I come back to my seat. No. It’s clear. The code has been erased. I look for the backup I usually have. What?! I have backed every file I’ve worked with, except this one.
Is my heart beating? Breathe. Relax. We can fix it.
I hit the “Back” button. For a second I see the code but WordPress reloads the page and takes it away. Cruel software… There I am, thinking of who to call to ask for a backup, help, something… No one. This was my responsibility and I just screwed up.
This time it was me. But next time it could be…
Lucky for you, I learned the hard way how to fix it. Hopefully you won’t go through this. But read along because, you never know.
Retreive the code from Google’s cache.
If your site has been indexed by search engines, you’ll be able to search for it and looked at a copy of the page you messed, the cache. Google is great for this. Find the page you messed up through Google. You’ll see a “Cached” link. Go to it.
Once you can see you’re old page, you can access the code through the “View Source” function. Voila.
But what if you erased dynamic code like PHP?
Thank God I didn’t. Otherwise I would be seriously screwed. If you erased php code the cached version won’t help you because the code won’t reflect the original source. You will see the executed php code.
You can’t hit back because WordPress will reload it automatically. What do you do?
You go into “Work Offline” mode first. THEN, you hit back and you’ll see a copy of the code. You won’t be able to copy it, so be prepared to capture the screen, take a picture, or do something so you can later rewrite the code by hand.
Hey, it might be a pain in the arse, but at least you didn’t lose it. That idea came to me AFTER I had hit the “Back “ button. So I was screwed either way.
If you have any other suggestions or ways to retrieve code, please let me know.
[ad]
christine says
Ahhhhhhh after you told me and I read it in your blog, guess what? I did the same thing. I think that the WordPress template editor is a bit dodgy. I was editing the header and added a line of javascript and poof, everything below that line of code disappeared. Luckily, I was able to re-write the code in a few minutes, but what a pain. Form now on, I’ll download the code via FTP and work on my local machine At least that way I can use the undo command.
Jose Uzcategui says
It IS dodgy, right? …and stressful at times. Downloading it is definitely a good idea. Since my incident I now copy/paste the code to my desktop every time I work on it.
Good to hear it was only a matter of minutes to fix the problem, though.
Take care!