This post may contain affiliate links for products discussed. As an Amazon Associate I earn from qualifying purchases. What this means is that by clicking one of these links, we may sometimes receive an affiliate fee.
If you’ve worked with WordPress for any extended period of time I’m sure you’ve had to add some custom code to the functions.php file. While it’s a common task in WordPress administration, it’s not necessarily the easiest or most fun thing to do. While we’ve done it the traditional way for too long, we’ve thankfully had great results with a newer, more modern method.
The traditional way of editing functions.php
Editing the functions.php file normally involves creating a child theme from your parent theme, copy over any Customizer settings that didn’t automatically carry over, and then edit the functions.php file in either the WordPress file editor, an FTP application, or your web host’s control panel’s file editor.
If you have certain WordPress security methods enabled you may find that your built-in file editor is actually not even functioning. This means that you’ll need to fire up an FTP client or load your web host’s control panel. Both are annoyingly slow when all you want to do is paste in some code you found on some random website and see if it works.
It’s not all bad, however, as this doesn’t require any extra overhead with plugins. It’s honestly not a terribly burdensome process, but do it enough times and you’ll be looking for a faster way for sure.
You’ll also notice that unless you use a child theme your changes get wiped out at each update of your WordPress theme. Some people forget about child themes and just update the live theme’s functions.php.
Using the child theme has long been the officially supported and endorsed method of updating the functions.php file, but there’s absolutely a better way to do this.
Editing functions.php with a snippets plugin
Actually, we aren’t even editing the file itself–not even in the child theme file. With a snippets plugin, you’re inserting your custom functions code directly into the site at the time of page load.
Our preferred plugin is called Code Snippets and is a much more flexible plugin than just updating your functions.php file. You can create snippets with different parameters and then toggle them off or on like you would a plugin.
You can drop in any PHP you would normally add to your functions.php file and you have a bit more control with this method than with editing the file directly.
When creating your snippet you can define how specifically to run the snippet–only in administration, only in the front-end, run everywhere, or run only once. This extra control is pretty helpful if you have code you only want to execute on a certain side of your website.
Final thoughts
We’ve been testing the Code Snippets plugin for quite a while on a few sites at this point and haven’t noticed any problems or performance hangups with this method. It’s made adding custom code to our sites a breeze and has arguably improved our experiences working in WordPress.
Have you had any experiences with using snippet plugins instead of manually editing WordPress files? If so, leave a comment down below and let us know!