How to remove type attributes for styles and scripts?
Problem: Markup Validation Service return warning message if your styles or scripts contain type attributes e.g.<style>
or <script>
Solution: We can use next code to resolve this problem:
<?php
// Remove type attribute from styles and scripts tags
add_action( 'wp_loaded', 'prefix_output_buffer_start' );
function prefix_output_buffer_start() {
ob_start( "prefix_output_callback" );
}
add_action( 'shutdown', 'prefix_output_buffer_end' );
function prefix_output_buffer_end() {
ob_end_flush();
}
function prefix_output_callback( $buffer ) {
return preg_replace( "%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%", '', $buffer );
}