When you are tasked with updating a WordPress site for a client or yourself, by far the most annoying part of the process can be maintaining the previous theme’s existing site functionality. Often, this is a daunting task for any WordPress newbie or professional alike. But fear not friends! There is a reliable solution for easing the pain, and that’s to create a custom functionality plugin. Think of it as an insurance policy against future time spent troubleshooting — proactive action now helps to eliminate potential headaches later.
Here at Razorfrog, for every new project we create a custom functionality plugin to ensure our code is easy to manage, manipulate and come back to from time to time. Creating a custom functionality plugin is a simple way for storing functions that you’d normally include within your child theme’s functions.php file. By keeping your non theme-dependent functions in a separate place, you no longer risk losing the functionality they have to offer when working with a new theme.
When Is It Appropriate To Use A Custom Functionality Plugin?
Any time you are working with a function that does not rely on your theme, you should include that function within your custom functionality plugin. Here’s a quick overview of when this is appropriate, and when to say functions.php is the best route.
Items to include within custom functionality plugins:
- Registering custom post types, taxonomies and meta fields
- Adding external functionality scripts
- Creating custom specified image sizes
- Customized login page details (logos, backgrounds, styling)
Items to leave out of custom functionality plugins:
- Enqueued fonts (think Google Fonts, Adobe Typekit, etc.)
- Theme-specific styling components
- Widget areas registered by a theme
- Customizations to header, footer and sidebars
- Layout specific functions
First, it is important to identity the various snippets, shortcodes and functions that are directly tied to your theme, as well as those that are not. This designation will ensure that, when the inevitable time comes for you to switch themes, you won’t be stuck with code fragments, lost content, and broken pages along the way.
Not sure how to get started? Create a folder in /wp-content/plugins/ with the name of your site (example: razorfrog). Inside that folder, create a PHP file matching the folder name (example: razorfrog.php). Then fire up your favorite text editor and copy/paste the following content there, making adjustments to the content as needed for your particular site:
<?php /* Plugin Name: Razorfrog Custom Functionality Plugin Plugin URI: https://razorfrog.com/ Description: Custom Post Types, Custom Taxonomies, Custom Meta. Version: 1.0 Author: Razorfrog Web Design Author URI: https://razorfrog.com/ Released under the GPLv2 license. */
Go ahead and start copying over all of those functions which you’d like to have included. Do not include any additional opening php tags. We recommend using comments to keep all snippets and functions well notated. You may want to include additional notes within your comments for improving collaboration with others on your team. Once ready to go live, you’ll need to activate this new plugin through WP Admin.
Keep Doing What You Do
There you have it! We hope that this short tutorial has helped you to learn a little more about best practices in the WordPress community. Have fun creating your site functionality plugin while keeping organized as you work.