In nearly every WordPress site I’ve worked on, there is some level of custom code needed. This can be for simple shortcodes all the way to prioritized hooks for WooCommerce or WordPress proper. In many how-tos you are instructed to add this custom code to the functions.php file for the site. While technically correct, in practice it can become problematic as you can lose your code in a large file, and it can be affected by upgrades to the site.
Enter Code Snippets. This handy plugin lets you create small “snippets” of code that are included in the site during rendering. There are some definite advantages to using this for modular code snippets:
- Ability to turn individual snippets on/off
You can define any number of code blocks, and selectively enable/disable them. This is great for debugging.
- Debugging right from the browser
This is both an advantage and slight disadvantage. Is it great that you can simply log into the WordPress admin and make your code changes, without the need to FTP files. However, this is a text editor within a browser, so it is limited compared to your normal editing application.
- Backed up in the database
The contents of these code fields is in the database, so when you back it up, you get your custom code as well.
- Will not get lost in functions.php file.
Using a plugin like this will help keep the functions.php file relatively clean. You can certainly still use custom code in functions.php in conjunction with the Code Snippets plugin, but the former you will need to open the file to see the code rather than just from within the Admin UI.
- Protection from upgrades
If you have an upgrade that may affect the functions.php file, or any other custom code for that matter, you can rest assured that the code stored in this plugin will be safe.
Overall it’s a simple, neatly packaged solution for a common developer problem. Check it out and post comments.