It depends on your goals. Putting it into your functions.php file means it will only work as long as that theme is active. It’s best to create a Custom Functionality plugin.
Here’s a few resources we’ve written on this subject:
1) That article you linked to references this snippet, which is actually it’s own stand-alone functionality plugin.
https://github.com/WordImpress/Give-Snippet-Library/blob/master/form-customizations/custom-fields-plugin.php
2) This article describes how to create (and WHY to create) your own Custom Functionality Plugin:
https://wordimpress.com/building-first-custom-functionality-plugin/
3) This article gives you a few resources that are more for beginners:
https://givewp.com/documentation/resources/adding-custom-functions-to-your-wordpress-website/
Let us know if you have any trouble at all.