0

Just tried to make an edit to the functions.php on my site. As is often the case, wp didn't like it and threw a fit, locking me out of making any further changes.

So now I have to use ftp to edit out the offending code.

You could argue I should be more careful / expert at coding, but the question is:

Isn't there an easier way to recover from messing up with a functions.php edit than having to ftp?

2 Answers 2

4

Here's a much better solution: Don't edit the theme's functions.php file. Don't put your custom code into that file either.

If you have snippets of code for a site, put them into a custom plugin. Put each one into its own plugin, in fact. Separate them by functionality.

I even made a handy dandy plugin to make this easier, called Pluginception.

The nice thing about editing plugins in the WordPress plugin edit screen: If you screw it up and cause a fatal error, WordPress will detect it and disable the plugin. This might break your site, but it probably won't break the admin screens and you can fix your error and reactivate the plugin.

Don't worry about the number of plugins. That's totally irrelevant. The code is what matters. The code has the same impact whether you put in a bunch of easily separated plugins or whether you shove it all together into one functions.php file that is dangerous to edit.

3
  • Thanks for the advice Otto - Trying to learn but so often the tut says "add this to functions.php".. Will try out your plugin - thanks! Jul 16, 2014 at 17:50
  • 1
    Please pass this link along anytime you see a tutorial suggesting that. Even I suggested this sort of thing in the past, however we were all wrong. Themes should remain themes and not receive random code for random reasons.
    – Otto
    Jul 16, 2014 at 18:04
  • Thanks to both who answered. I had thought there might be a way to avoid leaving the site and re-editing functions.php via ftp. Apparently not, but I have learned something more useful - to not develop in a live site environment, and also to not mess with the functions.php in the first place. I am marking Otto's answer as my preferred option because his plugin has given me a much better and safer way to experiment with new code and ideas. Thanks again to both :) Jul 16, 2014 at 20:40
3

Of course there are better ways to do that. You could use some local installation with a copy of your online website with software such as WAMP, XAMP, etc to make your changes.

"Cow Boy" coding is never a good solution. If you miss one ; boom! Fatal error! And in your case this is live.

You could also use better process such as git workflows to have a better control and roll back if there's some bug.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.