0

i need erase all type tag for styles and javascripts for my wordpress. I have this code and this work, but not 100%:

//* Remove type tag from script and style
add_filter('style_loader_tag', 'codeless_remove_type_attr', 10, 2);
add_filter('script_loader_tag', 'codeless_remove_type_attr', 10, 2);
add_filter('autoptimize_html_after_minify', 'codeless_remove_type_attr', 10, 
2);
function codeless_remove_type_attr($tag, $handle='')
 {
return preg_replace("/type=['\"]text\/(javascript|css)['\"]/", '', $tag);
}

Wen i tested in https://validator.w3.org/, i recived this fails:

Warning: The type attribute is unnecessary for JavaScript resources.

From line 54, column 3; to line 54, column 33

org' />↩        <script type="text/javascript">↩            wi

Warning: The type attribute for the style element is not needed and should 
be omitted.

From line 58, column 3; to line 58, column 25

script>↩        <style type="text/css">↩img.w

Warning: The type attribute for the style element is not needed and should 
be omitted.

From line 91, column 1; to line 91, column 37

t=xml" />↩<style type="text/css" media="print">#wpadm

Warning: The type attribute for the style element is not needed and should 
be omitted.

From line 92, column 1; to line 92, column 38

}</style>↩<style type="text/css" media="screen">↩   html

Warning: The type attribute is unnecessary for JavaScript resources.

From line 443, column 1; to line 443, column 31

</script>↩<script type='text/javascript'>↩/* <!

Warning: The type attribute is unnecessary for JavaScript resources.

From line 458, column 3; to line 458, column 33

]><!-->↩        <script type="text/javascript">↩

Can somebody help me? Thank

  • It’s just a warning. It didn’t “fail”. There’s nothing wrong, it’s just unnecessary. It’s not an issue worth spending any time on. – Jacob Peattie May 2 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.