Skip to content

Instantly share code, notes, and snippets.

@dakshhmehta
Last active May 20, 2020 12:30
Show Gist options
  • Save dakshhmehta/b983ff9a4348027590726c1b63ed460e to your computer and use it in GitHub Desktop.
Save dakshhmehta/b983ff9a4348027590726c1b63ed460e to your computer and use it in GitHub Desktop.
function __clean_js($tag, $handle) {
$__files = [
'async' => [
// 'recaptcha', // Plugin breaks
],
'defer' => [
'easy-testimonial',
'contact-form-7',
'themepunch',
],
];
$replace = false;
foreach ($__files as $mode => $files) {
foreach ($files as &$file) {
if(strpos($tag, $file) !== false){
$replace = $mode;
break;
}
}
}
if(! $replace){
return $tag;
}
return str_replace( ' src', ' '.$replace.' src', $tag );
}
add_filter('script_loader_tag', '__clean_js', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment