Skip to content

Instantly share code, notes, and snippets.

@chavesm
Created February 24, 2021 07:16
Show Gist options
  • Save chavesm/f5468769a08b29add7af35cdd0b06af6 to your computer and use it in GitHub Desktop.
Save chavesm/f5468769a08b29add7af35cdd0b06af6 to your computer and use it in GitHub Desktop.
WordPress filter hook that tries to remove unnecessary "text/javascript" and "text/css" from HTML source. Add to Child theme's functions.php.
<?php
/** Try to Remove Unnecessary "text/javascript" and "text/css" */
function codeless_remove_type_attr($tag, $handle) {
return preg_replace( "/type=['\"]text\/(javascript|css)['\"]/", '', $tag );
}
add_filter('style_loader_tag', 'codeless_remove_type_attr', 10, 2);
add_filter('script_loader_tag', 'codeless_remove_type_attr', 10, 2);
/** Credit: Codeless https://codeless.co/remove-type-attribute-from-wordpress/ */
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment