Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
//doplní všem skriptům, na kterých nejsou jiné závislé atributy async a defer
if (!is_admin()) {
add_filter('script_loader_tag', 'lynt_async_attr', 10, 3);
function lynt_async_attr($tag, $handle, $src)
global $wp_scripts;
$dependency = false;
$blacklist = ['smush-lazy-load'];
foreach ($wp_scripts->registered as $script) {
if (in_array($handle, $script->deps)) {
$dependency = true;
if ( !$dependency && !in_array($handle, $blacklist) ) {
return str_replace('src=', 'async defer src=', $tag);
return $tag;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment