Created
August 10, 2024 14:34
-
-
Save wp-seopress/36e68bede89ea7a80f7a0f9968a9ccad to your computer and use it in GitHub Desktop.
SEOPress.org defer scripts
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
<?php | |
//Defer JS | |
add_filter('script_loader_tag', 'seopress_add_async_defer', 10, 3); | |
function seopress_add_async_defer($tag, $handle, $src) | |
{ | |
$defer_scripts = array( | |
'global-scripts' | |
); | |
if (in_array($handle, $defer_scripts)) { | |
return '<script src="' . $src . '" defer type="text/javascript"></script>' . "\n"; | |
} | |
return $tag; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment