We occasionally ask our users to add custom code to their WordPress website to add simple features to Give. We do this because 80% of Give users don’t need that feature so we don’t want to add it to the core plugin. But where and how exactly are you supposed to add this custom code to your website? This article gives you an overview of why and how to do this right.
Dispelling the Myths of Custom Code in WordPress
Experienced developers know the best way to extend the functionality of a plugin is by adding their own code into what’s often called a “Functionality Plugin“. You might think that you can simply go into the plugin files and change them there. While it is true that you CAN do that, it’s not “best practice” because the next time your plugin is updated you will lose that custom code.
Another thing you’ll often hear is that you should just put this code into your theme’s `functions.php` file. Again, while this will work, it’s not considered “best practice” because your site most likely will update it’s theme in the near future and again you’ll lose that added functionality to the plugin once your theme changes.
So, the Give Support team gave you some custom code to use on your website, or you pulled it from our documentation. But you CAN’T change the plugin, you can’t add it to your theme’s `functions.php` file, and you don’t know how to create a Functionality Plugin. What are you supposed to do?
It is not "Best Practice" to put custom plugin code in your theme's functions.php file.
Use the “My Custom Functions” plugin
The “My Custom Functions” plugin is an easy and safe way to insert custom functions into your WordPress website without having to learn how to use a Custom Functionality plugin. Here’s the overview:
- Install My Custom Functions just like any other WordPress plugin
- After it is activated, go to “Appearance > Custom Functions”
- There you’ll see a textarea where you can add custom functions.
In the example below, I took some code from our documentation on making custom fields required, and inserted it into the textarea.
One really helpful feature of this plugin is that if you insert a function into the field and hit “Update” but there is something wrong with the function, it will disable it automatically and give you an alert like this:
With Great Power Comes Great Responsibility
We provide this documentation in order to help our Give users to add custom functions. Please be aware that this type of customization can create conflicts or issues on your website. We always highly recommend that you add custom functions in an environment that allows you to quickly undo what you’ve done without causing issues your live site. We also recomend you test thoroughly before going live. Here are a few important things to keep in mind