Remove Jetpack Dependency from child theme

Remove Jetpack Dependency

photo found on Unsplash

Nowadays there seems to be a tendency of theme authors to build themes that depend on Jetpack.

I would never include such a monstrosity into my theme, but the theme authors that choose to include are most often those that also include 15 sliders, 578 shortcodes and 1736 buttons (yes, I’m exaggerating).

So, what to do when the theme author wants you to use Jetpack, but you don’t want it on your site? Of course you can switch themes, but what if you happen to like a particular theme?

There are several ways to include a plugin into a theme or other plugin and for Jetpack, Automattic has written a dependency script.

Thing is though that although the script is comprehensive and comes with a plugin-enhancements.php file as well as a plugin-enhancements.js file, the README.md doesn’t mention anything about including the js file.

And if a theme author does not include that plugin-enhancements.js file, then the notice that the theme depends on Jetpack to function properly cannot be dismissed!

Long story short, how to remove the Jetpack dependency from you child theme if the theme author has forgotten to include the js file?

  1. write the theme author and inform him/her to include the file and re-submit the theme into the Repo
  2. add the following code snippet to the functions.php file of your child theme.
/**
 * Remove the Jetpack Dependency script from a parent theme
 * Some theme authors forget to include the plugin-enhancements.js file
 * Without it the notice that the theme depends on Jetpack cannot be dismissed
 *
 * Change "TEXTDOMAIN" on line 18 to the name of the parent theme.
 * Best to check the name in the plugin-enhancements.php file of the parent theme (usually the first line of the class)
 *
 * @source: //wpti.ps/?p=663
 */
 
 add_action( 'admin_head', 'bhi_remove_jetpack_dependency', 9 );

function bhi_remove_jetpack_dependency() {

	// Change "TEXTDOMAIN" to the name of the parent theme.
	remove_action( 'admin_head', array( 'TEXTDOMAIN_Theme_Plugin_Enhancements', 'init' ) );

}

Any Questions?