• Home
  • About Mitch
  • Speaking
  • Articles
  • Contact
  • Home
  • About Mitch
  • Speaking
  • Articles
  • Contact

Digital Strategist

WordPress Developer

Content Creator

Unapologetic Punk

Mitch Canter

  • X
  • Bluesky
  • GitHub
  • Twitch
  • YouTube
  • LinkedIn
Development

Functions.php Vs Writing a Plugin

CMDR Mitchcraft

Reading time: 2 minutes

When it comes to developing a new site, every developer has a stash of favorite code snippets or reusable modules they keep handy.  It could be a homemade widget, a section or module that is adaptable to multiple sites, or custom code that you use to personally extend the functionality of WordPress, but every developer worth their salt has them.  But over and over again I keep hearing the same question from new and old developers alike: Should these snippets be put into the functions.php file, or stored in a plugin?

What’s The Difference?

If you’re not familiar with it, the functions.php file is a special template file that stores any theme specific code that runs only when your theme (or a child theme) is activated.  Most times, pro themes will put all of their “on theme activation” codes, option panels, color pickers, and what-not in the functions.php file – or at least, in a file that’s included IN the functions.php file.

Plugins, on the other hand, will run no matter what theme you have.  You could change themes once a day for 30 days and still have the functionality of your plugin going strong.

Best Practices

The way I see it, there’s a fairly standard rule of thumb to use when it comes to this sort of thing: if you have a bit of functionality that needs to run on any theme, then it should go in a plugin.  If your functionality is theme specific and won’t transfer over to another theme, it should probably go into the theme’s functions.php file.

A Few Examples

Goes In A Plugin

  • Custom Post Type Setup
  • Custom Taxonomies
  • Google Analytics Code (if you add it via a hook to wp_footer() )
  • oEmbed extensions (Twitch, JustinTV, other services)

Goes in the Theme File

  • Custom Image Sizes
  • Javascript / Other Script Enqueues

The differences between these lists: The theme functions would stop working if the theme was switched, but  you’d still have Google Analytics, all your custom post types / taxonomies, and any extensions.

Agree? Disagree?  Have any special practices or rules of thumb you use for your own development?  Leave them in the comments below!

  • WordPress 2.7

    WordPress 2.7

    Reading time: 1 minute

    WordPress 2.7 is nothing short of amazing.  The WordPress team (and 150 others from the community) went back to the drawing board and redesigned the interface from the ground up.  It’s absolutely beautiful, and a testament to great design and an amazing user interface.  But it’s not just pretty, it’s awesome under the hood! Never…

    WordPress
  • WordPress Heartbeat API: An Introduction

    WordPress Heartbeat API: An Introduction

    Reading time: 2 minutes

    If I were to mention to a casual WordPress user something about the WordPress Heartbeat API, most would have never even heard of it, much less know that it’s been in WordPress since version 3.6(!) with very little fanfare.  But, as it turns out, the Heartbeat API has gained traction in the developer community, as…

    WordPress