WordPress code

A Template for your Functionality Plugin

| 3 Comments

I think I’ve made some good progress in trying to get people to convert from using their theme’s functions.php file for placing their code snippets to putting them in a unique functionality plugin.

There’s many good reasons for doing this, but high up on the list is portability (keep your snippets when you change themes, or sites) and retaining your code snippets if you ever need to upgrade your theme. If you want to read more, check out create a functionality plugin.

Well, if you want to go ahead and use a functionality plugin, but are scared about the code behind it, I’ve put a template together to make things exceptionally easy.

Install the plugin

All you need to do is download this plugin that I’ve put together and upload it to your site by going to Plugins > Add New > Upload. Once you’ve uploaded it, activate it (it will be called Functionality Plugin for SITENAME in your plugin list).

Personalise it for your site

Obviously, the plugin needs to be unique for your site, so you’ll need to customise it now. Go to Plugins > Editor and select Functionality Plugin for SITENAME.

Once you pull up the editor, you’ll see the header information already in place. All you’ll want to do is change SITENAME to your actual site name so that it’s clear what site it is for.

Then you’ll see a simple template for putting your snippets into. The way I like to do it, so that things are well organized and easy to sort through, is to put several line spaces between titles and snippets.

Keep your snippet titles capitalised so that they stand out when scrolling through the file. Remember, that since this is a PHP file, you must keep the titles commented (in between sets of //).

Also, if you ever want to disable a snippet, don’t delete it – change the title to include (DISABLED) and then comment out the snippet by putting /* before the snippet and */ after the snippet, as shown by example in the second snippet space in the template.

Does this help? Are you now more likely to use a functionality plugin? Help to spread the word!

Download the functionality plugin template

Categories: Code & Snippets, Resources & News | Permalink

What next?

Hire me

If you couldn't quite manage this yourself, find it too intimidating, or just don't have the time to do it, you can always hire Dave to do it. Please get in touch so that we can discuss your needs.

Leave a comment

If you have a question, update, or comment about the tutorial, please leave a comment. I try and respond to every comment, though it may take a few days, so please check back soon.

Let a WordPress Expert help you

Do you want to try this, but feel like you need a helping hand, in case something goes wrong? My service, The WP Butler, gives you access to WordPress expertise whenever you need it. Better yet, I'll keep your site backed up, updated and secure, so that you don't have to worry about it. It's all part of the service. Use coupon DIWW and save 15% on all plans.

Visit The WP Butler

Author:

Dave has been tinkering with WordPress for many years, and he now shares his WordPress knowledge here on Do It WIth WordPress to help others realise its impressive power. He can also be hired to help with your WordPress needs. Dave, who is British, is married to his best friend, Marti, with whom he has a beautiful daughter, Ellie. When he's not dabbling with WordPress, he's probably eating Triscuits or hummus, watching an indie film or British TV show, spending time with friends or family, or exploring the world.

3 Comments

  1. You raise a great point, Dave. It becomes really difficult to gather all those inserted codes when we decide to re-design a blog or upload a new theme. I believe the functionality plugin that you’re talking about can quickly remove our headaches.

    And the best part about it is that you can easily tailor the plugin to your specific requirements, as your site demands.

    Thanks for the useful share.

  2. That makes a lot of sense. A single misplaced semi-colon in functions.php can kill your site, so seems like another benefit to your plugin is that you can quickly correct syntax errors (or whatever errors) without having to scramble to FTP a fresh functions.php file to the server. :)

    Nicely done.

Leave a Reply