• 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: Switching to Drupal

    50 Days to a Better Blog–Day 5: Switching to Drupal

    Reading time: 1 minute

    I can’t even type this post with a straight face – nothing but love to all of my Drupal friends, though! It has its time and place, but for a blog, WordPress is always the way to go. The real Day 5 Post is coming soon.

    WordPress
  • 50 Days to a Better WordPress Blog–Day 1: Font Readability

    50 Days to a Better WordPress Blog–Day 1: Font Readability

    Reading time: 4 minutes

    When it comes to typography online, there are a few simple ideas you can remember to help your users read your articles time and time again and always be begging for more, without them having to get new glasses every time.

    WordPress