Skip to content

Instantly share code, notes, and snippets.

@jonbrockett
Created June 10, 2021 14:05
Show Gist options
  • Save jonbrockett/9c265adc604d886c1f2b9d607b24f1ae to your computer and use it in GitHub Desktop.
Save jonbrockett/9c265adc604d886c1f2b9d607b24f1ae to your computer and use it in GitHub Desktop.
Remove type= from <script> and <style>
/** Remove type= from <script> and <style> */
require_once 'library/type-remove.php';
<?php
/**
* Remove type= from <script> and <style>
*
* This will remove these HTML5 markup warnings
*/
//* Remove type tag from script and style
add_filter('style_loader_tag', 'remove_type_attr', 10, 2);
add_filter('script_loader_tag', 'remove_type_attr', 10, 2);
add_filter('autoptimize_html_after_minify', 'remove_type_attr', 10, 2);
function remove_type_attr($tag, $handle='')
{
return preg_replace("/type=['\"]text\/(javascript|css)['\"]/", '', $tag);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment