• 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!

  • 50 Days to a Better Blog–Day 5: Tags vs Categories (and more)

    50 Days to a Better Blog–Day 5: Tags vs Categories (and more)

    Reading time: 3 minutes

    This post is the fifth of an ongoing series entitled “50 Days to a Better WordPress Blog”.  During this time, Mitch will be providing small snippits of code, plugins, and things you can do to make your blog more attractive, attain new readers, and keep old ones coming back time and time again. You can…

    WordPress
  • WordPress Plugin: Author Spotlight

    WordPress Plugin: Author Spotlight

    Reading time: 2 minutes

    I’ve been doing a lot of looking into using WordPress as a multi-author website/blog lately.  A few of my clients have requested the need to handle (elegantly) multiple authors, so (being fresh on my mind) I feel inclined to share. One of the coolest plugin combinations I’ve come across recently is using Author Spotlight and…

    Tutorial, WordPress