I have seen a few articles in the past about WordPress functionality plugins, but I still see a lot of people neglecting to use them when they should. In this article I will touch on what they are, when you should use one, and how to create one.

What is a functionality plugin and why should I use one?

A functionality plugin will give you a place to add tweaks and code snippets to your WordPress website. A lot of site owners and theme developers put all of these into the theme's functions.php file. While functions.php does have a purpose, and theme specific functionality can be added here, it is a bad idea to rely only on this. The reason is simple: if you change themes, you lose all of the functionality with it.

A functionality plugin allows you to change the theme of your site, without losing all of your tweaks and customizations.

How can I create one?

If you haven't created a WordPress plugin before, don't be scared. If you've made changes to your theme before then you can handle creating a plugin. The first step is to open up a new file in your favorite IDE. Create a new file and save it in its own directory. Something like yoursite-functionality-plugin.php should do the trick.

All WordPress plugins should start with the standard plugin information. Copy and paste what I have below into your empty file and edit the information as needed:

<?php /* 
Plugin Name: Ryan Cowles' Functionality Plugin 
Plugin URI: http://ryanscowles.com/ 
Description: Important functions for ryanscowles.com 
Author: Ryan Cowles Version: 1.0 
Author URI: http://ryanscowles.com 
License: GPL2 */ 

// Your functions here ?>

Now you can start adding your functions to the file. For example, as you start adding, your plugin file may start to look something like this:

<?php /* 
Plugin Name: Ryan Cowles' Functionality Plugin 
Plugin URI: http://ryanscowles.com/ 
Description: Important functions for ryanscowles.com 
Author: Ryan Cowles 
Version: 1.0 
Author URI: http://ryanscowles.com 
License: GPL2 */ 

// Remove auto paragraphs from the excerpt  
remove_filter ('the_excerpt', 'wpautop'); 

// Remove auto paragraphs from the content  
remove_filter ('the_content', 'wpautop'); 

// Allow shortcodes in default text widget  
add_filter('widget_text', 'do_shortcode'); ?>

Include a Readme

It's also a good idea to include a Readme file with any plugin you create, even if it is only for your own reference. In the same directory that you created for your plugin, create a file called readme.txt. In that file, copy and paste the following, and edit the information to your content:

=== Ryan Cowles' Functionality Plugin ===
Requires at least: 3.5.1
Tested up to: 3.5.1
Stable tag: 1.0

Important functions for ryanscowles.com

== Description ==

This plugin is home to all of the important functions for ryanscowles.com.

== Changelog ==
= 1.0 =
* 02/2013: Created the plugin

Upload and activate your plugin

You are ready to upload your functionality plugin to your website! You can either zip your newly created files and upload them via Plugins –> Add New –> Upload in your WordPress Dashboard, or you can upload the plugin directory to /wp-content/plugins/.

Once this is done, you should be able to activate your plugin just as you would any other in your WordPress backend. Now, all the functions you add to your plugin will still work even if you change themes on your site.

When should I use functions.php?

Your theme's functions.php still has a purpose. It should be home to any functionality that is theme specific. For example, if you are registering sidebars or creating menus it should be done in functions.php, as these are directly related to the theme.

Conclusion

Like I said, I've seen a few articles about functionality plugins before, but I think more people should be aware about them and how easy it is to create one. What do you think?

References:

https://codex.wordpress.org/Writing_a_Plugin

http://www.doitwithwp.com/create-functions-plugin/

http://wpcandy.com/teaches/how-to-create-a-functionality-plugin/

Ryan Cowles

Ryan Cowles is a WordPress / Front End Developer living in Los Angeles, California. Along with a passion for building creative websites, he also enjoys photography, design, travel and the great outdoors. You can view his personal website by visiting http://ryanscowles.com. To see what he has been up to lately, check out his blog at Metacom Creative.

Ryan S. Cowles

You May Also Like

Comments are closed.