How to Remove the type Attribute from WordPress Script and Style Tags

In HTML5 the type attribute on <script> and <style> tags is redundant — text/javascript and text/css are the defaults. The W3C Markup Validator raises a warning for every such attribute, and older versions of WordPress and some plugins still output them. You can strip them with an output buffer filter.

Problem: WordPress adds type="text/javascript" and type="text/css" attributes to <script> and <link> tags, which are redundant in HTML5 and trigger warnings in HTML validators.

Solution: Use the script_loader_tag and style_loader_tag filters to strip the type attribute from enqueued assets. Target specific handles to avoid affecting third-party scripts that may legitimately include the attribute.

Add the following to your theme's functions.php or a site-specific plugin:

add_action( 'wp_loaded', 'start_output_buffer' );

function start_output_buffer() {
    ob_start( 'remove_type_attributes' );
}

add_action( 'shutdown', 'end_output_buffer', 0 );

function end_output_buffer() {
    if ( ob_get_level() > 0 ) {
        ob_end_flush();
    }
}

function remove_type_attributes( $html ) {
    return preg_replace(
        '/ type=["']text\/(javascript|css)["']/',
        '',
        $html
    );
}

A lighter alternative — filter the attributes at the WordPress level before the HTML is even rendered. WordPress 5.3+ provides the wp_script_attributes and wp_style_attributes filters:

// Remove from