How To Activate A Plugin Included In A Theme

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.

root directory

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.

			'name'     				=> 'Soliloquy', // The plugin name
			'slug'     				=> 'soliloquy', // The plugin slug (typically the folder name)
			'source'   				=> get_stylesheet_directory() . '/plugins/', // 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:

plugins folder

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.

required plugin

Install Required Plugins

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.

Never Miss a Tip from WP Sites

Get my latest web design tutorials, elegant coding solutions & useful tips.

5 Reasons Mad Mimi Works Better

  1. Sends From Your Email Address - More personal & higher open rate
  2. Cheapest - $42 for list of 10,000 emails, unlimited sends
  3. Ease of Use - The easiest system to create & setup campaigns
  4. RSS to E-Mail - Auto send list of latest posts
  5. Auto Send Any Number of Days - enables you to offer multiple newsletters at different frequencies.

Click here to create a free account.

Leave a Reply

Your feedback is always appreciated.

Your feedback is always welcome & appreciated however WP Sites does not reply to anonymous comment authors or approve loaded questions. Members get answers to unlimited questions.