Most people add useful code snippets to their WordPress site using their theme’s functions.php
file – simply add the code to the end and all is good. But there are a number of downsides to this solution which can be simply cured by converting them to a plugin. Let me explain why and how you can do this.
First of all the issues with using functions.php
…
- Your theme may also use this file so any update to your theme will cause all your own modifications to be lost
- It’s theme-specific so if you change to another theme at a later time, you need to copy over your changes to that theme’s file
- It’s harder to recover from a fatal error in this file than, say, one in a plugin
- When you have site issues and need to rule out code that could be causing it, you can’t disable this – if it’s a plugin you can temporarily disable this and ensure none of your changes are the cause
And that’s exactly what I do with this site – all my personal modifications are in a plugin named ‘Artiss.blog Configuration’.
To convert to a plugin, simply create a new .php
 file with your code in. Then add the following to the top…
Obviously, you’ll need to change the various bits of meta data to be appropriate to your site. But, otherwise, this can then be uploaded to your site as a plugin and activated as normal.