Last active
May 20, 2020 12:30
-
-
Save dakshhmehta/b983ff9a4348027590726c1b63ed460e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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