There are a lot of great code snippets floating around the web and this can be an easy way to add functionality to your website. With that said, there has been some controversy over whether it belongs in a plugin or your functions file. Of course there are arguments for both but in most cases I feel that it has a simple answer. If you can avoid modifying your current theme then you no longer have to fear losing features if and when you decide to update or change to another theme.
A very common mistake people make is relying on features included in premium themes such as portfolios and theme options. These are a lot of times built into themes to make things simple but can also keep you stuck using their product and lead to more problems down the road. This is in many cases is a real concern that can be avoided by not relying on the developers and taking control of your own content.
Let me explain. Say for instance you’re using a theme by a developer that decides to stop supporting theme updates. If you are using a portfolio that is directly tied into the theme itself, changing to another theme can leave you without a way to manage your content. What many people don’t know is that you can simply manage something like this with a plugin. This can be beneficial for multiple reasons but one of the most important besides insurance of your content is debugging.
Imagine the functions file of your theme with hundreds of lines of code. Now imagine trying to find an error while sifting though line after line. This can be avoided and simplified by managing custom code modifications in a plugin. Debugging is as simple as disabling the problematic plugin and moving on. You no longer have to worry about accidentally breaking your site and risking down time.
Build a plugin. I believe part of the reason people are adding snippets to their functions file is because they think that creating a plugin is difficult. In reality creating a plugin is quite simple and takes no more effort. I have provided the example code below to get you started. Simply add your information to the header and replace the function with your own. Save as a .php file and upload it to /wp-content/plugins/ of your WordPress site. Alternatively you can add the file to a zip folder and upload using the plugin uploader in your dashboard.
So next time you feel tempted to add another piece of code to your functions file I challenge you to take the extra step and create a plugin instead. This will take the fear out of future updates and let you rest easy knowing that your content is safe. For more information on writing plugins you can take a look at the WordPress codex.