Jetpack is a fantastic plugin for WordPress I’m sure we can all agree on that, there is a lot of debate about the excess bloat and as a developer I have to say Jetpack, as it is, is bloated and can really can bog your site down. One of the biggest problems I see is the conflict of Jetpack modules and built in features on themes. Theme developers should really take Jetpack into account and check to see if Jetpack modules are active and dequeue scripts for conflicting elements.
Below is an example of how we dequeue the Magnific Popup jQuery scripts and styles when the Jetpack Carousel module is active.
[php]
if ( class_exists( ‘Jetpack’ ) && Jetpack::is_module_active( ‘carousel’ ) ) {
wp_dequeue_script( ‘Magnific_popup’ );
wp_dequeue_style( ‘Magnific_popup_css’ );
}
[/php]
Remove a Jetpack Module completely
If you a shipping a theme that will have parts built in such as infinite scroll or maybe you have taken time to build an even better version of the Jetpack Carousel, you wont want your theme users to run into problems when activating Jetpack modules that wont be needed. Below is a simple method of removing Jetpack modules that aren’t needed from your site, you can add this a plugin or simply include it in your theme functions. This method is based on Parham Ghaffarian plugin.
[php]
function ah_remove_jetpack_modules( $modules ){
$jp_mods_to_disable = array(
‘related-posts’,
‘manage’,
‘protect’,
‘sso’,
‘mobile-push’,
‘photon’,
‘stats’,
‘gravatar-hovercards’,
‘minileven’,
‘vaultpress’,
‘custom-css’,
‘json-api’,
‘infinite-scroll’,
‘wpcc’,
// ‘shortcodes’,
// ‘widget-visibility’,
// ‘contact-form’,
// ‘shortlinks’,
// ’tiled-gallery’,
// ‘publicize’,
// ‘post-by-email’,
// ‘widgets’,
// ‘comments’,
// ‘latex’,
// ‘enhanced-distribution’,
// ‘notes’,
// ‘subscriptions’,
// ‘after-the-deadline’,
// ‘carousel’,
// ‘sharedaddy’,
// ‘omnisearch’,
// ‘likes’,
// ‘videopress’,
// ‘gplus-authorship’,
// ‘monitor’,
// ‘markdown’,
// ‘verification-tools’,
// ‘custom-content-types’,
// ‘site-icon’,
);
foreach ( $jp_mods_to_disable as $mod ) {
if ( isset( $modules[$mod] ) ) {
unset( $modules[$mod] );
}
}
return $modules;
}
add_filter( ‘jetpack_get_available_modules’, ‘ah_remove_jetpack_modules’ );
[/php]
To remove a module from Jetpack simple remove the comments, in the above example the first 14 modules have been deactivated completely.
Please leave your comments below.
sweet snippets. I know using functions is most efficient way, but I’m wondering if you have any ideas on how to control this on a multisite environment with the ability to enable/disable modules on a site by site basis. Probably asking too much, but might be an idea for a plugin… thanks
Hi Todd,
Good question. It depends on the multisite setup but easiest way would be to to use the function as a plugin and activate the plugin on a site to site basis not as a multisite plugin.
If you are running a small network you could use some conditionals to run the function on the site IDs you want.
On a large multisite project I would opt for the first option and just activate the plugin on the sites you want to disable JetPack modules on.
Hope that helps.
Hello ~ Awesome article ~ Thank You
My biggest problem with Jetpack plugin is in Jetpack Statistic module. I like Jetpack statistic but it stuck my page load time according to gtmetrix because of its Javascript.
I hope I can find any tutorial how to deal with jetpack statistic module, especially with divi theme.
There is an error again in “like” button monarch. prntscr . com/dwa4h2
I never tend to use the statistics Jetpack module, I found it never gave completely accurate stats and we use Google Analytics and CloudFlare on all sites anyway so I see stats from both of them. Plus with CloudCanvas we have Google Analytics integrated into the dashboard.