Make WordPress Core


Ignore:
Timestamp:
12/26/2025 01:14:22 PM (5 months ago)
Author:
jonsurrell
Message:

Scripts: Remove default type attribute from tags.

SCRIPT, STYLE, and stylesheet LINK tags do not require a type attribute since the HTML5 standard was released in 2008. Removing the type attribute simplifies logic and normalizes the produced HTML content.

Developed in https://github.com/WordPress/wordpress-develop/pull/10658.

Follow-up to [46164].

Props hardikhuptechdev, jonsurrell, dmsnell, westonruter.
Fixes #64428. See #59883, #64442.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-loader.php

    r61388 r61411  
    22062206    }
    22072207
    2208     $concat    = trim( $wp_scripts->concat, ', ' );
    2209     $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'";
     2208    $concat = trim( $wp_scripts->concat, ', ' );
    22102209
    22112210    if ( $concat ) {
    22122211        if ( ! empty( $wp_scripts->print_code ) ) {
    2213             echo "\n<script{$type_attr}>\n";
     2212            echo "\n<script>\n";
    22142213            echo "/* <![CDATA[ */\n"; // Not needed in HTML 5.
    22152214            echo $wp_scripts->print_code;
     
    22272226
    22282227        $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}" . $concatenated . '&ver=' . $wp_scripts->default_version;
    2229         echo "<script{$type_attr} src='" . esc_attr( $src ) . "'></script>\n";
     2228        echo "<script src='" . esc_attr( $src ) . "'></script>\n";
    22302229    }
    22312230
     
    23992398    }
    24002399
    2401     $concat    = trim( $wp_styles->concat, ', ' );
    2402     $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
     2400    $concat = trim( $wp_styles->concat, ', ' );
    24032401
    24042402    if ( $concat ) {
     
    24152413
    24162414        $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}" . $concatenated . '&ver=' . $ver;
    2417         echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "'{$type_attr} media='all' />\n";
     2415        echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "' media='all' />\n";
    24182416
    24192417        if ( ! empty( $wp_styles->print_code ) ) {
    2420             echo "<style{$type_attr}>\n";
     2418            echo "<style>\n";
    24212419            echo $wp_styles->print_code;
    24222420            echo sprintf( "\n/*# sourceURL=%s */", rawurlencode( $concat_source_url ) );
     
    29062904 */
    29072905function wp_get_script_tag( $attributes ) {
    2908     if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
    2909         // Keep the type attribute as the first for legacy reasons (it has always been this way in core).
    2910         $attributes = array_merge(
    2911             array( 'type' => 'text/javascript' ),
    2912             $attributes
    2913         );
    2914     }
    29152906    /**
    29162907     * Filters attributes to be added to a script tag.
     
    29542945 */
    29552946function wp_get_inline_script_tag( $data, $attributes = array() ) {
    2956     $is_html5 = current_theme_supports( 'html5', 'script' ) || is_admin();
    2957     if ( ! isset( $attributes['type'] ) && ! $is_html5 ) {
    2958         // Keep the type attribute as the first for legacy reasons (it has always been this way in core).
    2959         $attributes = array_merge(
    2960             array( 'type' => 'text/javascript' ),
    2961             $attributes
    2962         );
    2963     }
    2964 
    29652947    /*
    29662948     * XHTML extracts the contents of the SCRIPT element and then the XML parser
     
    29882970     */
    29892971    if (
    2990         ! $is_html5 &&
     2972        ! current_theme_supports( 'html5', 'script' ) &&
    29912973        (
    29922974            ! isset( $attributes['type'] ) ||
Note: See TracChangeset for help on using the changeset viewer.