@espacemusculation @humoba
This was also mentioned in https://ww.wp.xz.cn/support/topic/numerous-validation-errors-in-google-console/
What plugins do you have active? You probably have some theme or plugin that includes some logic to add the defer attribute for performance when it shouldn’t (since it already has async).
Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
I found this in my function file :
//to add defer to loading of scripts – use defer to keep loading order
function script_tag_defer($tag, $handle) {
if (is_admin()){
return $tag;
}
if (strpos($_SERVER[‘HTTP_USER_AGENT’], ‘MSIE 9.’) !==false) {
return $tag;
}
else {
return str_replace(‘ src’,’ defer src’, $tag);
}
}
add_filter(‘script_loader_tag’, ‘script_tag_defer’,10,2);
//to add defer to loading of scripts – use defer to keep loading order
Can you help me to add an exemption for amp file ??
Conditional To Output defer
Hi @espacemusculation,
Here’s a way to not output the defer attribute on AMP endpoints.
In place of:
else {
return str_replace( ' src', ' defer src', $tag );
}
use:
elseif ( ! function_exists( 'is_amp_endpoint' ) || ! is_amp_endpoint() ) {
return str_replace( ' src', ' defer src', $tag );
}
return $tag;
I had the same problem,
I use the Speed Booster plugin, and there is a option:
Defer parsing of javascript files
To resolve is just deselect this option, save and cleanup the cache.
[]´s