Everyone knows that you’re supposed to take a backup of important files like functions.php whenever you make a change. I suppose if you want to be really picky about it, you should be using some kind of version control system while modifying your WordPress files. In reality though, all of us cut corners to make changes that we think are completely trivial, and for the most part it works. Occasionally however, we pay the price for our carelessness. We’ve all experienced that feeling at some point of time – heart in the mouth, sinking denial – “This can’t be happening!”. Especially if it’s happening to you for the first time. But fear not! Even if you don’t know what exactly you messed up, here’s a quick way to recover WordPress from broken theme changes.
All you will need is access to an FTP editor. For its ease of use, I choose the FireFTP add-on for Firefox. In fact, it’s the only reason why I continue to have Firefox installed. For this article, I’m going to purposely break one of my themes and then show you how to revert it back – or at least get your site up and running again with another theme while you figure out what went wrong.
To start with, I’m going to artificially break my “Twenty Fourteen” WordPress theme. As you can see in the screenshot below, I went to my functions.php file in the WordPress editor and added a string of nonsense to the end of it.
Predictably, this throws WordPress into a tailspin and completely breaks my site. I just get a blank page – no error message, no debug info, nothing! Both the dashboard as well as my site have gone down.
This would be a good time to restore functions.php from a backup via FTP. Oh, I forgot – we have no backup! Well at least let’s first work on restoring our site with some other theme while we figure out how to fix this.
Renaming the Theme Folder
Using FTP, navigate to your WordPress blog folder, and into the “wp-content/themes” directory. Here you will see a list of themes you have installed with each getting its own separate folder. You can of course just delete the malfunctioning theme, but that seems a bit extreme. No, instead we’re just going to rename it to something else as shown below:
Once we do this, WordPress is no longer able to find the folder for the current theme and so deactivates it. We still haven’t restored our front-end yet, but our WordPress dashboard is now accessible. We can at least navigate to the themes section and activate a new one temporarily.
Fixing the Original Problem
This restores our blog to a working condition even though it may not be the form that we like. Now we finally have time to rectify our original mistake. If like me, you prefer to make changes directly into the WordPress file editing interface, let’s revert the functions.php in the Twenty Fourteen theme to its original state. Go over to the usual editor from the dashboard as shown below.
Now you have to select the malfunctioning theme from the drop-down box (in this case Twenty Fourteen) and hit “Select”. When the page reloads, scroll down and click the functions.php file to bring it up in the WordPress editor.
Right at the bottom we see our gobbledeegook which we can now safely delete and save. With this, we can now head back to our themes settings page and reactivate the original theme.
Mind you, this is just a quick fix. It is not a replacement for standard safety procedures such as backing up a file before making a change. It’s just that… well you know, sometimes bad things just happen! You always need to be able to Recover WordPress if any hacks happen or you lose your webhost.