Skip to content

Commit 9cbb060

Browse files
committed
Trac #64428: Remove default type attributes from SCRIPT and STYLE elements
1 parent 102c39b commit 9cbb060

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

src/wp-includes/script-loader.php

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ function _print_scripts() {
22062206
}
22072207

22082208
$concat = trim( $wp_scripts->concat, ', ' );
2209-
$type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'";
2209+
$type_attr = '';
22102210

22112211
if ( $concat ) {
22122212
if ( ! empty( $wp_scripts->print_code ) ) {
@@ -2399,7 +2399,7 @@ function _print_styles() {
23992399
}
24002400

24012401
$concat = trim( $wp_styles->concat, ', ' );
2402-
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
2402+
$type_attr = '';
24032403

24042404
if ( $concat ) {
24052405
$dir = $wp_styles->text_direction;
@@ -2905,12 +2905,8 @@ function wp_sanitize_script_attributes( $attributes ) {
29052905
* @return string String containing `<script>` opening and closing tags.
29062906
*/
29072907
function 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-
);
2908+
if ( isset( $attributes['type'] ) && 'text/javascript' === $attributes['type'] ) {
2909+
unset( $attributes['type'] );
29142910
}
29152911
/**
29162912
* Filters attributes to be added to a script tag.
@@ -2953,13 +2949,8 @@ function wp_print_script_tag( $attributes ) {
29532949
* @return string String containing inline JavaScript code wrapped around `<script>` tag.
29542950
*/
29552951
function 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-
);
2952+
if ( isset( $attributes['type'] ) && 'text/javascript' === $attributes['type'] ) {
2953+
unset( $attributes['type'] );
29632954
}
29642955

29652956
/*
@@ -2987,15 +2978,12 @@ function wp_get_inline_script_tag( $data, $attributes = array() ) {
29872978
* @see https://www.w3.org/TR/xhtml1/#h-4.8
29882979
*/
29892980
if (
2990-
! $is_html5 &&
2991-
(
2992-
! isset( $attributes['type'] ) ||
2993-
'module' === $attributes['type'] ||
2994-
str_contains( $attributes['type'], 'javascript' ) ||
2995-
str_contains( $attributes['type'], 'ecmascript' ) ||
2996-
str_contains( $attributes['type'], 'jscript' ) ||
2997-
str_contains( $attributes['type'], 'livescript' )
2998-
)
2981+
! isset( $attributes['type'] ) ||
2982+
'module' === $attributes['type'] ||
2983+
str_contains( $attributes['type'], 'javascript' ) ||
2984+
str_contains( $attributes['type'], 'ecmascript' ) ||
2985+
str_contains( $attributes['type'], 'jscript' ) ||
2986+
str_contains( $attributes['type'], 'livescript' )
29992987
) {
30002988
/*
30012989
* If the string `]]>` exists within the JavaScript it would break

0 commit comments

Comments
 (0)