Hi, my name is
Lee Harris and
I'm a Freelance Web Designer

Remove “type” attribute from script tags in WordPress

17.Dec.2017 | ,

Fed up of getting the W3 Validator warning “The type¬†attribute is unnecessary…”?

Here is a handy bit of code to remove the type attributes (and anything else) from WordPress. Add this to your functions.php file and customise. Then you’re good to go!

add_action( 'template_redirect', function(){
    ob_start( function( $buffer ){
        $buffer = str_replace( array( '', "" ), '', $buffer );
        
        // Also works with other attributes...
        $buffer = str_replace( array( '', "" ), '', $buffer );
        $buffer = str_replace( array( '', "" ), '', $buffer );
        $buffer = str_replace( array( '', "" ), '', $buffer );
        
        return $buffer;
    });
});

, , ,

  • html5
  • css3
  • sass
  • php
  • WordPress
  • WooCommerce