How to Disable Jetpack Modules Like a Pro

Jetpack is one of those plugins that people love to hate. Let’s be honest, it’s bloated. It has a lot of options in it and a ton of features that, in my opinion, probably would be better off in separate plugins. That said, there are some really useful aspects of Jetpack, and I’ve used it on a quite a few occasions.

We’re actually using it here on WP Site Care because it’s the best WordPress plugin for social sharing that we’ve found to date. It’s fast, relatively easy to style, and doesn’t add a ton of bloat to your posts and pages when they’re loading.

Since I’d like to be able to use some of the functionality in Jetpack, I’ve tried to find ways to use it without loading everything. Last week, I came across a great post by Jeremy Herve on how to change the way Jetpack loads some of its modules. He does an awesome job explaining how they’ve built in tons of filters to allow developers to interact with Jetpack. He even provides some sample code for unsetting modules that you don’t want to activate.

One thing that I felt the post was lacking was a list of the modules currently available in Jetpack, so I did a bit of code hackery and got the list myself. In order to follow along with this post, you’ll obviously need to download and install Jetpack first. You can do so by clicking the banner bellow or simply by searching for “Jetpack” from the add new plugin screen on your WordPress install.

Once I had the list of modules, I started using Jeremy’s code to block modules that I didn’t want to load. As is typical of me, I found myself thinking about alternative ways to disable unwanted Jetpack modules and I think I’ve got another option that will work well for lots of people.

The idea behind this is to prevent unwanted Jetpack modules from being loaded either by yourself or other administrators on your site. The following code doesn’t actually disable Jetpack modules; rather it hides them from being used at all. Before adding this snippet to your theme or a functionality plugin you’ll want to manually deactivate each module from the Jetpack admin screen.

Once you’ve disabled the modules you want to hide, all you need to do is add the following code to your plugin or your theme’s functions.php file and you’ll have a boilerplate for removing any Jetpack module you don’t want loading on your site.

<?php
add_filter( 'jetpack_get_available_modules', 'prefix_hide_jetpack_modules' );
/**
* Disable all non-whitelisted jetpack modules.
*
* As it's written, this will allow all of the currently available Jetpack
* modules to work display and be activated normally.
*
* If there's a module you'd like to disable, simply comment it out or remove it
* from the whitelist and it will no longer be available for activation.
*
* @author WP Site Care
* @link   http://www.wpsitecare.com/disable-jetpack-modules/
* @param  array $modules the existing list of Jetpack modules
* @return array $modules the amended list of Jetpack modules
*/
function prefix_hide_jetpack_modules( $modules ) {
	// A list of Jetpack modules which are allowed to activate.
	$whitelist = array(
		'after-the-deadline',
		'carousel',
		'comments',
		'contact-form',
		'custom-content-types',
		'custom-css',
		'enhanced-distribution',
		'gravatar-hovercards',
		'infinite-scroll',
		'json-api',
		'latex',
		'likes',
		'manage',
		'markdown',
		'minileven',
		'monitor',
		'notes',
		'omnisearch',
		'photon',
		'post-by-email',
		'protect',
		'publicize',
		'related-posts',
		'sharedaddy',
		'shortcodes',
		'shortlinks',
		'site-icon',
		'sso',
		'stats',
		'subscriptions',
		'tiled-gallery',
		'vaultpress',
		'verification-tools',
		'videopress',
		'widget-visibility',
		'widgets',
	);
	return array_intersect_key( $modules, array_flip( $whitelist ) );
}

That’s really all there is to it. The only thing you’ll need to do is remove any modules listed in the $whitelist variable and they will be disabled. I’ve included all presently available modules in the whitelist so you can choose to remove whichever one you like without having to figure out which modules are available.

It should also be noted that this will disable any new modules which are added to Jetpack. If they’re not in the whitelist, they won’t be available for activation or deactivation.

Control Jetpack With Plugins!

While you’re at it, you might also want to install this awesome plugin by Mark Jaquth. It’s a little old, but it still works like a charm. Basically it tells any plugins which activate a menu at the top of your WordPress admin sidebar to get back where they belong, at the bottom. Content before settings please!

Another cool Jetpack-related plugin that will give you more control over the way Jetpack modules are loaded is called Rocketeer. According to the plugin author Brady Vercher, Rocketeer let’s you manage Jetpack modules much like you do plugins. The prmiary features include sorting and bulk activation/deactivation of Jetpack modules. Download it and check it out!

If you have any questions or would like to suggest other things for us to publish about Jetpack, please leave them in the comments.



Leave a Reply