Don’t Put That In Functions.php!

Or, How to Write A Basic Plugin
Kailey Lampert

You’re all too familiar with copying all those top-10 latest-and-greatest best-tricks-you’ve-never-heard-of snippets from various tutorial sites into your theme’s functions.php file. What could be easier? Copy a few lines of code, just paste it in, and you’re good-to-go, right?


I’m not knocking those kinds of posts at all, they often have very handing bits of code, but the functions.php file is in your theme because it’s for your theme. If your snippets/code are “theme-agnostic” – adding functionality that should persist regardless of the theme, like custom shortcodes or widgets – functions.php is the wrong place for it. You’ll risk losing that functionality if you ever update or switch themes.

So we’ll start with a simple code snippet, make it work without using functions.php, and step-by-step turn it into a shiny plugin using best-practices.