If you’re a theme Developer, you may have a very good reasons to include a specific plugin in your parent or child theme.
Firstly, lets take a look at one of the best ways to include a plugin in a child theme.
The method i used recently for a theme developer was to use the TGM Plugin Activation function.
TGM Plugin Activation
Once added to your theme and configured, these files automatically install and activate plugins from within themes.
There’s only 2 files you need to deal with even though you’ll find many more in the zip file once downloaded from Github.
Where To Put The File & Code
class-tgm-plugin-activation.php – You can add this file to your themes root directory or anywhere in your theme.
Here’s what it looks like in my theme on my test site.
example.php – You can copy all the PHP code from this file and paste it at the end of your child themes functions.php file. You’ll then need to change the settings in the code.
Example Code Settings
Here’s the only part of the code from the example.php file which has been configured in my functions file.
array( 'name' => 'Soliloquy', // The plugin name 'slug' => 'soliloquy', // The plugin slug (typically the folder name) 'source' => get_stylesheet_directory() . '/plugins/soliloquy.zip', // The plugin source 'required' => true, // If false, the plugin is only 'recommended' instead of required 'version' => '', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented 'force_activation' => true, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch 'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins 'external_url' => '', // If set, overrides default API URL and points to an external URL ), ); // Change this to your theme text domain, used for internationalizing strings $theme_text_domain = 'lifesytyle-pro';
All you need to do then is create a new folder in your child theme named plugins and upload the zip file for the plugin to that new folder.
Here’s the file structure which shows you how i do it:
In this example i have added the zip folder for the Soliloquy slider plugin to the plugins folder.
Whenever this theme is activated, a message will now prompt the installer to install and activate the plugin.
Install Required Plugins
This is not the only way to include plugins in themes however its one of the best and has been developed by 2 well respected Developers:
Gary Jones & Thomas Griffin.Subscribe for Genesis Tutorials - Double Opt In Confirmation Required