Last active
March 23, 2023 03:39
-
-
Save pavelrich/af79bc9283a4edd1ec85c8bf2ea1f674 to your computer and use it in GitHub Desktop.
WordPress — Remove 'type' Attribute of Scripts and Styles
This file contains 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 | |
if ( ! function_exists( 'prefix_remove_type_attr' ) ) { | |
/** | |
* Remove 'type' Attribute of Scripts and Styles | |
*/ | |
function prefix_remove_type_attr( $tag ) { | |
return preg_replace( "/type=['\"]text\/(javascript|css)['\"]/", '', $tag ); | |
} | |
add_filter( 'style_loader_tag', 'prefix_remove_type_attr', 10 ); | |
add_filter( 'script_loader_tag', 'prefix_remove_type_attr', 10 ); | |
add_filter( 'autoptimize_html_after_minify', 'prefix_remove_type_attr', 10 ); // 'Autoptimize' plugin support | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment