Skip to content

Instantly share code, notes, and snippets.

@pavelrich
Last active March 23, 2023 03:39
Show Gist options
  • Save pavelrich/af79bc9283a4edd1ec85c8bf2ea1f674 to your computer and use it in GitHub Desktop.
Save pavelrich/af79bc9283a4edd1ec85c8bf2ea1f674 to your computer and use it in GitHub Desktop.
WordPress — Remove 'type' Attribute of Scripts and Styles
<?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