Created
April 10, 2024 09:52
-
-
Save marcwieland95/ef62a55d8c2d819280a3c9011eb068b3 to your computer and use it in GitHub Desktop.
Load Legacy Script via WordPress for old browser (nomodule)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('wp_enqueue_scripts', function() { | |
wp_register_script( | |
'scripts-legacy', | |
get_template_directory_uri() . '/build/scripts-legacy.js', | |
['jquery'], | |
getenv('GIT_COMMIT_SHORT_SHA'), | |
true | |
); | |
// For legacy browser | |
wp_enqueue_script('scripts-legacy'); | |
}, 1); | |
add_filter('script_loader_tag', function($tag, $handle, $src) { | |
if ($handle === 'scripts-legacy') { | |
$tag = '<script defer nomodule type="text/javascript" src="' . esc_url($src) . '"></script>'; | |
}, 50, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment