This is a very simple way for you to build your first WordPress plugin. Basically, you can use this for every WordPress snippet, hack and mod that you would normally drop in your theme’s functions.php file.
If your modifications are theme dependent, like creating sidebars and menus, keep your functions.php edits in your theme.
However, if you’re creating shortcodes, adding custom post types/taxonomies, WordPress Dashboard customizations, etc … , build yourself a Functionality plugin.
It’s easy.
Here’s how:
Create Your Own WordPress Functionality Plugin
After I did this the first time, I felt so cool.
Step 1
Create a folder and name it whatever you like, as long as it doesn’t interfere with any of your plugins.
Example: my-custom-functions
Step 2
Open your favorite text editor and create a new document.
Drop in this code:
[cc lang=”php”][/cc]
Add your snippet, hack or mod that you would normally have in your functions.php
Save it as a relevant file name in the folder you created in Step 1.
Example: my-custom-functions.php
Step 3
FTP your new folder in your wp-content/plugins directory.
Open up your WordPress admin and look for your newly created Functionality Plugin listed with all of your other plugins. Once you find it, enable it and watch the magic!
Conclusion
There’s a number of ways you can go about using this. You can pile-up all your mods into one Functionality Plugin, or you can split them up individually. This is really handy if you’re regularly building sites. You can create a “tool-belt” of options and add whatever edits you want or need in a particular project. If there are some standard things you like to do on every build, bundle them into one Functionality Plugin and use it as a starting point for every project.
Although this isn’t the slickest solution for WordPress maintenance, whenever I need to test some changes and want to quickly and easily throw WordPress into maintenance mode, I enable my “simple maintenance mode” Functionality Plugin.
[cc lang=”php”]/*Simple Maintenance Mode*/
function cwc_maintenance_mode() {
if ( !current_user_can( ‘edit_themes’ ) || !is_user_logged_in() ) {
wp_die(‘We are doing some maintenance, please come back soon!’);
}
}
add_action(‘get_header’, ‘cwc_maintenance_mode’);[/cc]
I also find a Functionality Plugin to be very useful when creating custom post types, too.
Here are a few posts to get some Functionality Plugin inspiration:
- 5 Easy-to-Add WordPress Shortcodes
- Display Hidden WordPress Visual Editor Buttons
- 6 WordPress Login Modifications
- Customize Your WordPress Login Screen
- 4 Quick WordPress Hacks (That Are Easier Than a Plugin)
Have fun!
Andre Barnes says
Really loving the WordPress stuff Eric. Thank you posting.
Eric Dye says
That’s great to hear, thanks!
Carl Franzon says
I have seen some suggest that number of plugins should be limited because it slows the site down.
Is there any difference in site speed if you do it the way you described vs. having a series of lines like this in your functions.php:
require_once ($functions_path . ‘my-custom-functions.php’);
Not sure if the way I suggest above would be faster.
Your way certainly makes it easier to make changes because you can just use the plugin admin vs. having to go in and edit your functions.php file.
Eric Dye says
I’ve wondered about this, too. I think it has a lot to do with the size of the plugin, too, since most are far heavier than functions. As for your method, I’m not sure. Test it? I usually end up combining my functions into one functions plugin. If I’m adding something new, I test and try it separately, and then add it in after it’s been cruising fine for a while.
jatinder says
hey, Eric Dye!,
Its helpful method to develop plugin, but I have question, I have two plugins say, “jQuery Lightbox For Native Galleries” and “sharethis” plugins, i want both functionality works together when the images shown in light box their must come share option to share the current image, any clue for it,
thanks , and waiting for reply,
regards: Jatinder Saini
Eric Dye says
I wish it were as easy as combining some code all into one! This could probably be done, but it’s going to take more coding chops than I’ve got.
jatinder says
Thanks for reply man,
Will you help me out what should i have to do for this?? any reference or method that should i have to use..
Regards: Jatinder
Eric Dye says
It’s not a quick and easy thing. I would recommend Google searches and getting a tighter hold on how to right WordPress plugins.
Jatinder says
thanks, for you help, I appreciate it.
Eric Dye says
Sure thing. 🙂