Skip to content

Instantly share code, notes, and snippets.

@wp-seopress
Created August 10, 2024 14:34
Show Gist options
  • Save wp-seopress/36e68bede89ea7a80f7a0f9968a9ccad to your computer and use it in GitHub Desktop.
Save wp-seopress/36e68bede89ea7a80f7a0f9968a9ccad to your computer and use it in GitHub Desktop.
SEOPress.org defer scripts
<?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