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.

Built from https://develop.svn.wordpress.org/trunk@61411


git-svn-id: http://core.svn.wordpress.org/trunk@60723 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
jonsurrell
2025-12-26 13:16:34 +00:00
parent 4b738b966a
commit 5e1414562a
30 changed files with 46 additions and 150 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ add_action( 'wp_head', 'do_activate_header' );
*/
function wpmu_activate_stylesheet() {
?>
<style type="text/css">
<style>
.wp-activate-container { width: 90%; margin: 0 auto; }
.wp-activate-container form { margin-top: 2em; }
#submit, #key { width: 100%; font-size: 24px; box-sizing: border-box; }
+1 -1
View File
@@ -3946,7 +3946,7 @@ function wp_ajax_parse_media_shortcode() {
$styles = wpview_media_sandbox_styles();
foreach ( $styles as $style ) {
$head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
$head .= '<link rel="stylesheet" href="' . $style . '">';
}
if ( ! empty( $wp_scripts ) ) {
+1 -1
View File
@@ -606,7 +606,7 @@ function install_plugin_information() {
$low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
$high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
?>
<style type="text/css">
<style>
#plugin-information-title.with-banner {
background-image: url( <?php echo esc_url( $low ); ?> );
}
+1 -1
View File
@@ -451,7 +451,7 @@ function wp_privacy_generate_personal_data_export_file( $request_id ) {
fwrite( $file, "<html>\n" );
fwrite( $file, "<head>\n" );
fwrite( $file, "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n" );
fwrite( $file, "<style type='text/css'>" );
fwrite( $file, '<style>' );
fwrite( $file, 'body { color: black; font-family: Arial, sans-serif; font-size: 11pt; margin: 15px auto; width: 860px; }' );
fwrite( $file, 'table { background: #f0f0f0; border: 1px solid #ddd; margin-bottom: 20px; width: 100%; }' );
fwrite( $file, 'th { padding: 5px; text-align: left; width: 20%; }' );
+1 -1
View File
@@ -335,7 +335,7 @@ if ( ! function_exists( 'twentyeleven_header_style' ) ) :
// If we get this far, we have custom styles. Let's do this.
?>
<style type="text/css" id="twentyeleven-header-css">
<style id="twentyeleven-header-css">
<?php
// Has the text been hidden?
if ( 'blank' === $text_color ) :
+1 -1
View File
@@ -38,7 +38,7 @@ if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
?>
</title>
<link rel="profile" href="https://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="<?php echo esc_url( get_stylesheet_uri() ); ?>?ver=20251202" />
<link rel="stylesheet" media="all" href="<?php echo esc_url( get_stylesheet_uri() ); ?>?ver=20251202" />
<link rel="pingback" href="<?php echo esc_url( get_bloginfo( 'pingback_url' ) ); ?>">
<?php
/*
@@ -95,7 +95,7 @@ if ( ! function_exists( 'twentyfifteen_header_style' ) ) :
// If we get this far, we have custom styles. Let's do this.
?>
<style type="text/css" id="twentyfifteen-header-css">
<style id="twentyfifteen-header-css">
<?php
// Short header for when there is no Custom Header and Header Text is hidden.
if ( empty( $header_image ) && ! display_header_text() ) :
@@ -69,7 +69,7 @@ if ( ! function_exists( 'twentyfourteen_header_style' ) ) :
// If we get this far, we have custom styles.
?>
<style type="text/css" id="twentyfourteen-header-css">
<style id="twentyfourteen-header-css">
<?php
// Has the text been hidden?
if ( ! display_header_text() ) :
@@ -349,7 +349,7 @@ function twentynineteen_colors_css_wrap() {
}
?>
<style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
<style id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
<?php echo twentynineteen_custom_colors_css(); ?>
</style>
<?php
@@ -443,7 +443,7 @@ function twentyseventeen_colors_css_wrap() {
$customize_preview_data_hue = 'data-hue="' . $hue . '"';
}
?>
<style type="text/css" id="custom-theme-colors" <?php echo $customize_preview_data_hue; ?>>
<style id="custom-theme-colors" <?php echo $customize_preview_data_hue; ?>>
<?php echo twentyseventeen_custom_colors_css(); ?>
</style>
<?php
@@ -77,7 +77,7 @@ if ( ! function_exists( 'twentyseventeen_header_style' ) ) :
// If we get this far, we have custom styles. Let's do this.
?>
<style id="twentyseventeen-custom-header-styles" type="text/css">
<style id="twentyseventeen-custom-header-styles">
<?php
// Has the text been hidden?
if ( 'blank' === $header_text_color ) :
@@ -90,7 +90,7 @@ if ( ! function_exists( 'twentysixteen_header_style' ) ) :
// If the header text has been hidden.
?>
<style type="text/css" id="twentysixteen-header-css">
<style id="twentysixteen-header-css">
.site-branding {
margin: 0 auto 0 0;
}
+1 -1
View File
@@ -275,7 +275,7 @@ if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
*/
function twentyten_admin_header_style() {
?>
<style type="text/css" id="twentyten-admin-header-css">
<style id="twentyten-admin-header-css">
/* Shows the same border as on front end */
#headimg {
border-bottom: 1px solid #000;
+1 -1
View File
@@ -39,7 +39,7 @@ if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
?>
</title>
<link rel="profile" href="https://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="<?php echo esc_url( get_stylesheet_uri() ); ?>?ver=20251202" />
<link rel="stylesheet" media="all" href="<?php echo esc_url( get_stylesheet_uri() ); ?>?ver=20251202" />
<link rel="pingback" href="<?php echo esc_url( get_bloginfo( 'pingback_url' ) ); ?>">
<?php
/*
@@ -96,7 +96,7 @@ function twentythirteen_header_style() {
// If we get this far, we have custom styles.
?>
<style type="text/css" id="twentythirteen-header-css">
<style id="twentythirteen-header-css">
<?php
if ( ! empty( $header_image ) ) :
?>
@@ -77,7 +77,7 @@ function twentytwelve_header_style() {
// If we get this far, we have custom styles.
?>
<style type="text/css" id="twentytwelve-header-css">
<style id="twentytwelve-header-css">
<?php
// Has the text been hidden?
if ( ! display_header_text() ) :
+4 -33
View File
@@ -105,37 +105,12 @@ class WP_Styles extends WP_Dependencies {
*/
public $default_dirs;
/**
* Holds a string which contains the type attribute for style tag.
*
* If the active theme does not declare HTML5 support for 'style',
* then it initializes as `type='text/css'`.
*
* @since 5.3.0
* @var string
*/
private $type_attr = '';
/**
* Constructor.
*
* @since 2.6.0
*/
public function __construct() {
if (
(
function_exists( 'is_admin' ) &&
! is_admin()
)
&&
(
function_exists( 'current_theme_supports' ) &&
! current_theme_supports( 'html5', 'style' )
)
) {
$this->type_attr = " type='text/css'";
}
/**
* Fires when the WP_Styles instance is initialized.
*
@@ -184,9 +159,8 @@ class WP_Styles extends WP_Dependencies {
if ( $inline_style ) {
$inline_style_tag = sprintf(
"<style id='%s-inline-css'%s>\n%s\n</style>\n",
"<style id='%s-inline-css'>\n%s\n</style>\n",
esc_attr( $handle ),
$this->type_attr,
$inline_style
);
} else {
@@ -232,12 +206,11 @@ class WP_Styles extends WP_Dependencies {
$title = isset( $obj->extra['title'] ) ? $obj->extra['title'] : '';
$tag = sprintf(
"<link rel='%s' id='%s-css'%s href='%s'%s media='%s' />\n",
"<link rel='%s' id='%s-css'%s href='%s' media='%s' />\n",
$rel,
esc_attr( $handle ),
$title ? sprintf( " title='%s'", esc_attr( $title ) ) : '',
$href,
$this->type_attr,
esc_attr( $media )
);
@@ -264,12 +237,11 @@ class WP_Styles extends WP_Dependencies {
}
$rtl_tag = sprintf(
"<link rel='%s' id='%s-rtl-css'%s href='%s'%s media='%s' />\n",
"<link rel='%s' id='%s-rtl-css'%s href='%s' media='%s' />\n",
$rel,
esc_attr( $handle ),
$title ? sprintf( " title='%s'", esc_attr( $title ) ) : '',
$rtl_href,
$this->type_attr,
esc_attr( $media )
);
@@ -365,9 +337,8 @@ class WP_Styles extends WP_Dependencies {
}
printf(
"<style id='%s-inline-css'%s>\n%s\n</style>\n",
"<style id='%s-inline-css'>\n%s\n</style>\n",
esc_attr( $handle ),
$this->type_attr,
$output
);
+5 -9
View File
@@ -5897,10 +5897,9 @@ function _wp_theme_json_webfonts_handler() {
function print_embed_styles() {
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_embed_styles' );
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
$suffix = SCRIPT_DEBUG ? '' : '.min';
$suffix = SCRIPT_DEBUG ? '' : '.min';
?>
<style<?php echo $type_attr; ?>>
<style>
<?php echo file_get_contents( ABSPATH . WPINC . "/css/wp-embed-template$suffix.css" ); ?>
</style>
<?php
@@ -5922,9 +5921,8 @@ function print_emoji_styles() {
$printed = true;
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
?>
<style<?php echo $type_attr; ?>>
<style>
img.wp-smiley,
img.emoji {
display: inline !important;
@@ -5949,9 +5947,8 @@ function print_emoji_styles() {
*/
function wp_admin_bar_header() {
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_header_styles' );
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
?>
<style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style>
<style media="print">#wpadminbar { display:none; }</style>
<?php
}
@@ -5963,9 +5960,8 @@ function wp_admin_bar_header() {
*/
function _admin_bar_bump_cb() {
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_bump_styles' );
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
?>
<style<?php echo $type_attr; ?> media="screen">
<style media="screen">
html { margin-top: 32px !important; }
@media screen and ( max-width: 782px ) {
html { margin-top: 46px !important; }
+1 -44
View File
@@ -61,32 +61,6 @@ class WP_Font_Face {
*/
private $valid_font_display = array( 'auto', 'block', 'fallback', 'swap', 'optional' );
/**
* Array of font-face style tag's attribute(s)
* where the key is the attribute name and the
* value is its value.
*
* @since 6.4.0
*
* @var string[]
*/
private $style_tag_attrs = array();
/**
* Creates and initializes an instance of WP_Font_Face.
*
* @since 6.4.0
*/
public function __construct() {
if (
function_exists( 'is_admin' ) && ! is_admin()
&&
function_exists( 'current_theme_supports' ) && ! current_theme_supports( 'html5', 'style' )
) {
$this->style_tag_attrs = array( 'type' => 'text/css' );
}
}
/**
* Generates and prints the `@font-face` styles for the given fonts.
*
@@ -227,24 +201,7 @@ class WP_Font_Face {
* @return string The style element.
*/
private function get_style_element() {
$attributes = $this->generate_style_element_attributes();
return "<style class='wp-fonts-local'{$attributes}>\n%s\n</style>\n";
}
/**
* Gets the defined <style> element's attributes.
*
* @since 6.4.0
*
* @return string A string of attribute=value when defined, else, empty string.
*/
private function generate_style_element_attributes() {
$attributes = '';
foreach ( $this->style_tag_attrs as $name => $value ) {
$attributes .= " {$name}='{$value}'";
}
return $attributes;
return "<style class='wp-fonts-local'>\n%s\n</style>\n";
}
/**
+1 -1
View File
@@ -3921,7 +3921,7 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) {
}
?>
<title><?php echo $title; ?></title>
<style type="text/css">
<style>
html {
background: #f1f1f1;
}
+2 -2
View File
@@ -5061,7 +5061,7 @@ function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
}
$stylesheet_link = sprintf(
"<link rel='stylesheet' href='%s' type='text/css' />\n",
"<link rel='stylesheet' href='%s' />\n",
esc_url( wp_admin_css_uri( $file ) )
);
@@ -5080,7 +5080,7 @@ function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
if ( function_exists( 'is_rtl' ) && is_rtl() ) {
$rtl_stylesheet_link = sprintf(
"<link rel='stylesheet' href='%s' type='text/css' />\n",
"<link rel='stylesheet' href='%s' />\n",
esc_url( wp_admin_css_uri( "$file-rtl" ) )
);
+1 -3
View File
@@ -2871,10 +2871,8 @@ function gallery_shortcode( $attr ) {
* Otherwise, defaults to true.
*/
if ( apply_filters( 'use_default_gallery_style', ! $html5 ) ) {
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
$gallery_style = "
<style{$type_attr}>
<style>
#{$selector} {
margin: auto;
}
+1 -1
View File
@@ -94,7 +94,7 @@ function graceful_fail( $message ) {
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Error!</title>
<style type="text/css">
<style>
img {
border: 0;
}
+7 -25
View File
@@ -2205,12 +2205,11 @@ function _print_scripts() {
$zip = 'gzip';
}
$concat = trim( $wp_scripts->concat, ', ' );
$type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'";
$concat = trim( $wp_scripts->concat, ', ' );
if ( $concat ) {
if ( ! empty( $wp_scripts->print_code ) ) {
echo "\n<script{$type_attr}>\n";
echo "\n<script>\n";
echo "/* <![CDATA[ */\n"; // Not needed in HTML 5.
echo $wp_scripts->print_code;
echo sprintf( "\n//# sourceURL=%s\n", rawurlencode( 'js-inline-concat-' . $concat ) );
@@ -2226,7 +2225,7 @@ function _print_scripts() {
}
$src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}" . $concatenated . '&ver=' . $wp_scripts->default_version;
echo "<script{$type_attr} src='" . esc_attr( $src ) . "'></script>\n";
echo "<script src='" . esc_attr( $src ) . "'></script>\n";
}
if ( ! empty( $wp_scripts->print_html ) ) {
@@ -2398,8 +2397,7 @@ function _print_styles() {
$zip = 'gzip';
}
$concat = trim( $wp_styles->concat, ', ' );
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
$concat = trim( $wp_styles->concat, ', ' );
if ( $concat ) {
$dir = $wp_styles->text_direction;
@@ -2414,10 +2412,10 @@ function _print_styles() {
}
$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}" . $concatenated . '&ver=' . $ver;
echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "'{$type_attr} media='all' />\n";
echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "' media='all' />\n";
if ( ! empty( $wp_styles->print_code ) ) {
echo "<style{$type_attr}>\n";
echo "<style>\n";
echo $wp_styles->print_code;
echo sprintf( "\n/*# sourceURL=%s */", rawurlencode( $concat_source_url ) );
echo "\n</style>\n";
@@ -2905,13 +2903,6 @@ function wp_sanitize_script_attributes( $attributes ) {
* @return string String containing `<script>` opening and closing tags.
*/
function wp_get_script_tag( $attributes ) {
if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
// Keep the type attribute as the first for legacy reasons (it has always been this way in core).
$attributes = array_merge(
array( 'type' => 'text/javascript' ),
$attributes
);
}
/**
* Filters attributes to be added to a script tag.
*
@@ -2953,15 +2944,6 @@ function wp_print_script_tag( $attributes ) {
* @return string String containing inline JavaScript code wrapped around `<script>` tag.
*/
function wp_get_inline_script_tag( $data, $attributes = array() ) {
$is_html5 = current_theme_supports( 'html5', 'script' ) || is_admin();
if ( ! isset( $attributes['type'] ) && ! $is_html5 ) {
// Keep the type attribute as the first for legacy reasons (it has always been this way in core).
$attributes = array_merge(
array( 'type' => 'text/javascript' ),
$attributes
);
}
/*
* XHTML extracts the contents of the SCRIPT element and then the XML parser
* decodes character references and other syntax elements. This can lead to
@@ -2987,7 +2969,7 @@ function wp_get_inline_script_tag( $data, $attributes = array() ) {
* @see https://www.w3.org/TR/xhtml1/#h-4.8
*/
if (
! $is_html5 &&
! current_theme_supports( 'html5', 'script' ) &&
(
! isset( $attributes['type'] ) ||
'module' === $attributes['type'] ||
+2 -2
View File
@@ -23,11 +23,11 @@ _deprecated_file(
<title><?php echo wp_get_document_title(); ?></title>
<link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>" media="screen" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php if ( file_exists( get_stylesheet_directory() . '/images/kubrickbgwide.jpg' ) ) { ?>
<style type="text/css" media="screen">
<style media="screen">
<?php
// Checks to see whether it needs a sidebar.
+2 -5
View File
@@ -733,12 +733,9 @@ function locale_stylesheet() {
return;
}
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
printf(
'<link rel="stylesheet" href="%s"%s media="screen" />',
$stylesheet,
$type_attr
'<link rel="stylesheet" href="%s" media="screen" />',
$stylesheet
);
}
+1 -1
View File
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.0-alpha-61410';
$wp_version = '7.0-alpha-61411';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
@@ -55,12 +55,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
return;
}
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
printf(
'<style%s>.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>',
$type_attr
);
echo '<style>.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>';
}
/**
+1 -1
View File
@@ -176,7 +176,7 @@ function login_header( $title = null, $message = '', $wp_error = null ) {
$classes[] = 'interim-login';
?>
<style type="text/css">html{background-color: transparent;}</style>
<style>html{background-color: transparent;}</style>
<?php
if ( 'success' === $interim_login ) {
+1 -1
View File
@@ -63,7 +63,7 @@ do_action( 'before_signup_header' );
*/
function wpmu_signup_stylesheet() {
?>
<style type="text/css">
<style>
.mu_register { width: 90%; margin: 0 auto; }
.mu_register form { margin-top: 2em; }
.mu_register fieldset,