Site Specific Plugin vs. Functions.php

Site Specific Plugin vs. Functions.php – a discussion that I often read or hear is whether to use a site specific plugin versus including the code into a theme’s functions.php file. In this article, I am going to discuss them both and provide my point of view. In the example, I am going to use the following snippet of code, which forces WordPress to not compress JPG uploads.

// Prevent JPG Compressions
add_filter('jpeg_quality', function($arg){return 100;});

wordpress plugin vs function.php

Site Specific Plugin

A site specific plugin is WordPress plugin file that you create specifically for your website. For example, I am a New Jersey photographer who has created a bunch of custom post types. One of which is for a proofing gallery that clients will view. I used a custom post type so the WordPress SEO plugin will automatically hide galleries from search engines.

Now, in order to make the function happen, I created a site specific plugin that creates the custom post types. In addition to that piece of code, I also added the snippet (above) that keeps the JPG quality at 100%. This is what the plugin looks like:

<?php
/* Plugin Name: Your Plugin Title Goes Here
Description: Site specific code changes for YourDomain.com
*/
/* Start Adding Functions Below this Line */
// Prevent JPG Compressions
add_filter('jpeg_quality', function($arg){return 100;});
/* Stop Adding Functions Below this Line */
?>

I then saved the code as yourdomain-plugin.phpand uploaded it to my WordPress plugin folder. Once activated, the compression snippet worked. Adding in my custom post type code made that function work as well.

Functions.php

Every WordPress theme has a functions.php file, which is used to perform various functions in the theme or in WordPress overall. On top of that, the file can be edited manually to add or change functionality to the user’s liking. Typically a person would not modify a theme’s functions.php and if so desired, would do it using a child theme as to not harm the parent theme. To see some of what you can do with the functions.php file, check out this article at WP Beginner.

If you were to add a snippet, like the one above, to your functions.php file it would look like this:

<?php
/* Start Adding Functions Below this Line */
// Prevent JPG Compressions
add_filter('jpeg_quality', function($arg){return 100;});
/* Stop Adding Functions Below this Line */
?>

Similar, right? So this is where my personal logic and opinion comes in. Let’s say, hypothetically, that you are using one of the many photography website templates available. Six months after using one of the themes, you decide to switch. What happens if the modifications and snippets you made to a functions.php file? Simple – they get lost.

In Summary

So, in my eyes, I’d rather create a site specific plugin that will keep any and all of my modifications no matter what plugin I am using. Now, that isn’t to say you should never use the functions.php file. In fact, for certain things I would encourage it.

For example, before coming on board at Photocrati, I was using a StudioPress theme. Having used one of the best theme frameworks out there, it was a change to go to a WordPress plugin that was designed for a specific niche. Also, being a person with my own WordPress OCD, I decided to make some fun modifications to my Photocrati child theme. These changes are done in the functions.php file because they’re specific to the theme, not to the site. One final recap:

  • Use a site specific plugin if your modifications should keep no matter what theme you’re using
  • Use functions.php if the modifications are specific to the active theme on your website

I hope this helped explain some things for you. For more on plugins vs. themes, please read Pippin Williamson’s article, Functionality: Plugins vs Themes or one from Tom Ewer, Ask the Experts: Should Themes Include Plugin-Style Functionality?.

Thanks for reading.

- Written by Scott Wyden Kivowitz -

He is the Community & Blog Wrangler at Photocrati, developer of the WordPress theme for photographers, NextGEN Gallery and the Photographers SEO Community, teaching other photographers on how to increase business with their website.

2 Comments to “Site Specific Plugin vs. Functions.php”

Add Comments (+)

  1. thanks fot this helpful post. i did not jeard about this snippet before..

  2. Chris says:

    I manage such snippets neither with “thousands” of plugins nor with editing the functions.php. There’s a great solution: http://wordpress.org/extend/plugins/code-snippets/
    One single plugin manages all your snippets and you can turn some snippets on or off, just how you like. No editing of files, no installation of several plugins. I love it!

Leave a Reply

 

Amazingly Beautiful WordPress Themes