Have you ever been browsing through the theme viewer or checking out the daily theme release announcements over at WeblogToolsCollection.com, and noticed that a certain theme requires a plugin to function correctly (or at least has a feature that requires a plugin to work)? I certainly have, and although I have never required a plugin for any themes I've released, I can see why one would want to include the functionality of a plugin to make that theme even more awesomely cool (and perhaps get more downloads).
But it is generally frowned upon to require the user to download and install a plugin in order for your theme to work properly. So what is a designer to do? Of course, he could just try to figure out what the plugin does by examining the code, but most designers don't have a working knowledge of PHP/MySQL. Another option is to just remove the feature from your theme, but that means you lose that super-cool feature that might have set your theme apart from the others.
Thankfully, there is a solution that is actually quite simple.
A while back, I was working on a custom design for a client, and he requested a very long list of features that were beyond what I could do with a vanilla WordPress install. So naturally, I hit google up for any plugins that would give me the functionality he was looking for. But again, I wanted to deliver a fully functional theme to this client, without having to instruct him to install a list of plugins to get the theme working properly.
After thinking for a while, it hit me: just copy the code from the plugin into the functions.php file of the WordPress theme. I did so, and it worked like a charm! Absolutely no plugins were activated, and I was able to deliver a theme that worked perfectly right out of the box.
A few possible limitations to this method.
I'm not sure about this, but some plugins do add new rows/columns/tables to your database. There is a possibility that a plugin will do this upon activation, and may not work as an integrated function in the functions.php file. Again, I'm not sure about this.
Also, plugins with multiple files, especially plugins that require you place files/folders in multiple locations, probably won't be easily integrated into your theme. Plugins that only require a single file upload are best.
A few extra tips
- Be sure to keep the plugin information in tact when copying the content of a plugin file over to your functions.php file. This way you can keep track of which plugins are installed, and where one ends and another begins.
- Be sure to copy the entire contents of the plugin file to your functions.php file. If you're missing an opening or closing tag anywhere, it could break your theme.
- Use obvious separators when integrating multiple plugins. This is sort of like point 1, but you'll definitely want to use a consistent and obvious marker for when a plugin begins and ends.
- Test, Test, TEST!!! Do not just slap the code in last minute and expect it to work. Test it extensively and make sure that your theme doesn't break. Plugins are buggy sometimes, so you need to make sure it's working properly before you release it or make it live.
One Final Tip
If you are comfortable enough with PHP, it should be noted that you can put the plugin files in a folder within your theme folder, and simply use your functions.php file to include those plugin files. I like to keep the php calls to a minimum, but you're certainly welcome to go that route if you are more comfortable with it.
Anyway, I thought that was a cool little tip, and hopefully so will you.
Happy Coding!














