Skip to content

Instantly share code, notes, and snippets.

@bordoni
Last active November 14, 2023 05:52
Show Gist options
  • Save bordoni/da3dac90c83c2f84109c98077edc9af4 to your computer and use it in GitHub Desktop.
Save bordoni/da3dac90c83c2f84109c98077edc9af4 to your computer and use it in GitHub Desktop.
Resolves a problem that surfaced between Event Tickets and WordPress version `6.4.1`.
add_filter( 'script_loader_tag', static function( $tag, $handle ) {
if ( ! class_exists( 'Tribe__Assets', false ) ) {
return $tag;
}
$assets = Tribe__Assets::instance();
$asset = $this->get( $handle );
// Only filter for own filters.
if ( ! $asset ) {
return $tag;
}
// Bail when not dealing with JS assets.
if ( 'js' !== $asset->type ) {
return $tag;
}
// When not module we bail with the tag.
if ( ! $asset->module ) {
return $tag;
}
// Remove the type attribute if it exists.
preg_match( "/ *type=['\"]{0,1}[^'\"]+['\"]{0,1}/i", $tag, $matches );
if ( ! empty( $matches ) ) {
$tag = str_replace( $matches[0], ' ', $tag );
}
$replacement = '<script type="module" ';
return str_replace( '<script ', $replacement, $tag );
}, 200, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment