Tutorials, Wordpress

Remove type attribute from script and style tags added by WordPress

30 July 2018

While validating the W3C, we need to remove “type” attribute from script and style which were added by WordPress.

The style_loader_tag and script_loader_tag approaches above look like they should work for whatever markup WordPress is generating, in cases where the theme/plugin is using the proper enqueue functions.

If you have offending plugins that don’t cooperate (IIRC Jetpack is/was an offender unless a newer version since my recollection has revised this!), and you are adamant about solving this issue despite the fact that your visitors are not likely to be impacted in any way (their browser will render the page fine!), you can always go all-out and use output buffering:

add_action('wp_loaded', 'output_buffer_start');
function output_buffer_start() { 

add_action('shutdown', 'output_buffer_end');
function output_buffer_end() { 

function output_callback($buffer) {
    return preg_replace( "%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%", '', $buffer );

Leave a Comments