logoBrett Rawlins

Where to put your custom WordPress functions

August 9, 2013

I found a great WordPress tip while reading some articles today. Often when you're trying to solve a problem you'll find code snippets in a tutorial or blog post somewhere, and they usually tell you to paste the code into your theme's functions.php file. While that works for the time being, it's probably not the best idea because as soon as you change your theme you'll lose that functionality too.

A better idea is to write your own plugin that holds any custom functionality that is specific to your site and that also needs to be independent of whatever theme you choose. This goes by various names such as a "site-specific plugin", "functionality plugin", or "custom functions plugin". The above links provide a good walk-through on how to write your plugin.

Credit to Justin Tadlock for the additional tip of making it a "must-use plugin". Must-use plugins are automatically loaded so they don't have to be activated/deactivated. It's as simple as putting it in a new subfolder at wp-content/mu-plugins instead of wp-content/plugins.