WordPress Theme Functionality Without Invading the Plugin Territory

WordPress Theme Functionality Without Invading the Plugin Territory

There’s a concept in WordPress theme making, called “the plugin territory”. Basically, WordPress forbids themes to offer functionality because then it restrains users from switching themes. And it’s a pretty big deal, because the two biggest theme repositories–WordPress.org Theme Directory and ThemeForest–complies with this concept to set the quality of the themes high, meaning you can’t submit a theme that invades the plugin territory.

But the concept includes essential theme functionality like shortcodes, custom post types, sliders and such. So, how do we deal with this and make our themes abide by the plugin territory? In this mini-tutorial, I’m going to show you how.

Understanding the Plugin Territory

The “Plugin Territory” page includes a variety of funcionality. Things like analytics, SEO options, sharing buttons, caching or Admin Bar changes are already considered “things that plugins should handle”, but things like shortcodes, custom post types, custom taxonomies, favicons or custom widgets are sometimes essential to theme development. After all, you can’t create sliders without custom post types, right?

Wrong. You have to think from the point of your customers, the theme users. They should have the liberty of switching themes at all times, and you can’t force them to use your theme forever. What if they’re using a theme for logged-in users and another theme for visitors? What if they need to switch themes every week for some reason? Heck, what if they like changing themes every single day?

There is a rule of thumb that you can always abide by: If a user switches a theme, they can’t lose any part of their websites. That is, they shouldn’t build their website over and over again every time they switch themes.

So, how do you let them keep their shortcodes, widgets and sliders even after they stop using your theme?

Making Your Themes Functional Without Invading the Plugin Territory

A logical solution would be offering your theme’s functionality as plugins. So, yeah. That’s it.

Kidding. You can (and should) offer plugins along with your theme, to serve your theme’s functionality. But how? If your theme needs those functionality in order to work properly, you should warn–nay–require your users to install and activate them.

Enter TGM Plugin Activation. This library focuses solely on this “plugin territory” issue and lets you recommend or require plugins. The plugins could be bundled with your theme files, fetched from the WordPress.org Plugin Repository or even downloaded (automatically) from an external URL.

And integrating TGMPA is fairly simple:

  • Download a customized version of TGMPA from the Download page.
  • Place the class-tgm-plugin-activation.php file anywhere in your theme directory.
  • Call the file in your functions.php file with require_once().
  • Create a function to configure TGMPA (like this) and hook the function to the tgmpa_register action.
  • That’s all!

Wrapping Up

While TGM Plugin Activation looks like a “workaround” to the plugin territory concept, it actually complies with it and helps you to do so.

What do you think about the concept of “plugin territory” and the TGM Plugin Activation library? Tell us what you think by commenting below. And thanks for reading!

We're part of the Asquared WordPress Agency. All rights reserved.