Remove type attribute from script and style tags

Remove type attribute from script and style tags Remove type attribute from script and style tags, to improve The W3C Markup Validation, and ranking of website. Remove type attribute from…

Remove type attribute from script and style tags

Remove type attribute from script and style tags, to improve The W3C Markup Validation, and ranking of website. Remove type attribute from script and style tags.

The following code was worked for me, please try this code into you function.php file to Remove type attribute from script and style tags.

copy the code

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 );
}

copy the code

Hope its works for you, tested on WordPress version 5.4.2 and php version 7.3. :)

0 Comments
Leave a comment