Skip to content

Instantly share code, notes, and snippets.

@felixarntz
Created September 27, 2023 04:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixarntz/500e465b1f864e3b67d1882af969739c to your computer and use it in GitHub Desktop.
Save felixarntz/500e465b1f864e3b67d1882af969739c to your computer and use it in GitHub Desktop.
Jetpack uselessly enqueues Thickbox JS (which itself enqueues jQuery!) when rendering the Subscriptions block, even though it doesn't even use Thickbox. I use this snippet on my own site to fix it.
<?php
/**
* Fix Jetpack Subscriptions block to not uselessly enqueue Thickbox, which in turn enqueues jQuery.
*/
function felixarntz_stop_jetpack_subscriptions_from_enqueuing_thickbox_without_any_usage() {
if ( wp_script_is( 'jetpack-block-subscriptions' ) && isset( wp_scripts()->registered['jetpack-block-subscriptions'] ) ) {
$script = wp_scripts()->registered['jetpack-block-subscriptions'];
$index = array_search( 'thickbox', $script->deps, true );
if ( false !== $index ) {
unset( $script->deps[ $index ] );
$script->deps = array_values( $script->deps );
}
// Also add 'defer' since this script does not need to be _immediately_ loaded.
$script->add_data( 'strategy', 'defer' );
// This here is needed since sometimes that script is generally enqueued as well.
// Probably not needed?
if ( wp_script_is( 'thickbox' ) ) {
wp_dequeue_script( 'thickbox' );
}
}
}
add_action( 'wp_enqueue_scripts', 'felixarntz_stop_jetpack_subscriptions_from_enqueuing_thickbox_without_any_usage' );
add_action( 'wp_footer', 'felixarntz_stop_jetpack_subscriptions_from_enqueuing_thickbox_without_any_usage' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment