Wouldn’t it be great if all the plugins you’d normally use are ready and waiting for you to install when you activate your child theme? Well, with the TGM Plugin Activation library it’s a breeze to do so. After including the library into your child theme, you’ll be presented with a message which will prompt you to install the plugins you’ve specified.

Get off to a flying start with TGM Plugin Activation

TGM is a PHP library that allows you to reference plugins from the WordPress Plugin repository, plugins bundled with a theme, or even plugins hosted elsewhere on the internet.

Okay, enough of an introduction. Let’s get to it.

Using the Custom TGMPA Generator

The first step is to navigate to the Custom TGMPA Generator where you’ll be presented with the following screen:

There are two things you need to do here, first select the Child Theme radio button and then enter the Text Domain (alphanumeric and dashes accepted). Entering the Text Domain automatically populates the Function Prefix and Name fields with the same information. Once you’ve done these two simple steps, select the Generate button and save the resulting file to your machine.

Editing and Using the PHP Files

Okay, this is where the fun starts but it’s really not hard. In a few simple steps, you’ll be ready to rock-and-roll.

Begin by unzipping the file you’ve just downloaded. Now create a folder in your child theme*. You can call it anything but in my example, I’ve call it inc. Now copy  class-tgm-plugin-activation.php and example.php to this folder. Rename example.php to tgm_pa.php.

The next step is to edit the functions.php of your child theme. Add the following code to the bottom of this page:

Now go back to tgm_pa.php and update the path to class-tgm-plugin-activation.php. On roughly line 34 you should find the following:

Change this to:

At this point, you’re ready to start editing the tgm_pa.php file. As daunting as this file may seem, it’s really quite easy to modify it to include the plugins you need. Begin by looking for $plugins = array() which should be on about line 60. The file includes detailed comments which make it easier to follow. If you’re going to be pulling your plugins from the WordPress Plugin Repository you can remove most of the code between the opening and closing brackets of this section. The following is an example of how to include the Jetpack plugin:

Remember that you can pull plugins from a variety of sources. Check out the detailed comments in the examples provided in the file for more instructions of how to use each of them.

Now that you’ve edited all the necessary files you can go ahead and zip up your child theme and upload and activate it on your site. On activation you’ll see a message that says “This theme recommends the following plugins” and you can now proceed to install these plugins.

Conclusion

And that folk is how easy it is to present yourself or your client with a quick and easy way of installing suggested and required plugins.

*If you need help creating a child theme, head on over to Divi Life and follow their Divi Child Theme guide. Child themes are considered best practice in order to safely customize a theme’s files.