Search Blog

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( 'type="text/javascript"', "type='text/javascript'" ), '', $buffer );
        
        // Also works with other attributes...
        $buffer = str_replace( array( 'type="text/css"', "type='text/css'" ), '', $buffer );
        $buffer = str_replace( array( 'frameborder="0"', "frameborder='0'" ), '', $buffer );
        $buffer = str_replace( array( 'scrolling="no"', "scrolling='no'" ), '', $buffer );
        
        return $buffer;
    });
});