Make WordPress Core


Ignore:
Timestamp:
12/26/2025 01:14:22 PM (4 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/class-wp-styles.php

    r61397 r61411  
    107107
    108108    /**
    109      * Holds a string which contains the type attribute for style tag.
    110      *
    111      * If the active theme does not declare HTML5 support for 'style',
    112      * then it initializes as `type='text/css'`.
    113      *
    114      * @since 5.3.0
    115      * @var string
    116      */
    117     private $type_attr = '';
    118 
    119     /**
    120109     * Constructor.
    121110     *
     
    123112     */
    124113    public function __construct() {
    125         if (
    126             (
    127                 function_exists( 'is_admin' ) &&
    128                 ! is_admin()
    129             )
    130             &&
    131             (
    132                 function_exists( 'current_theme_supports' ) &&
    133                 ! current_theme_supports( 'html5', 'style' )
    134             )
    135         ) {
    136             $this->type_attr = " type='text/css'";
    137         }
    138 
    139114        /**
    140115         * Fires when the WP_Styles instance is initialized.
     
    185160        if ( $inline_style ) {
    186161            $inline_style_tag = sprintf(
    187                 "<style id='%s-inline-css'%s>\n%s\n</style>\n",
     162                "<style id='%s-inline-css'>\n%s\n</style>\n",
    188163                esc_attr( $handle ),
    189                 $this->type_attr,
    190164                $inline_style
    191165            );
     
    233207
    234208        $tag = sprintf(
    235             "<link rel='%s' id='%s-css'%s href='%s'%s media='%s' />\n",
     209            "<link rel='%s' id='%s-css'%s href='%s' media='%s' />\n",
    236210            $rel,
    237211            esc_attr( $handle ),
    238212            $title ? sprintf( " title='%s'", esc_attr( $title ) ) : '',
    239213            $href,
    240             $this->type_attr,
    241214            esc_attr( $media )
    242215        );
     
    265238
    266239            $rtl_tag = sprintf(
    267                 "<link rel='%s' id='%s-rtl-css'%s href='%s'%s media='%s' />\n",
     240                "<link rel='%s' id='%s-rtl-css'%s href='%s' media='%s' />\n",
    268241                $rel,
    269242                esc_attr( $handle ),
    270243                $title ? sprintf( " title='%s'", esc_attr( $title ) ) : '',
    271244                $rtl_href,
    272                 $this->type_attr,
    273245                esc_attr( $media )
    274246            );
     
    366338
    367339        printf(
    368             "<style id='%s-inline-css'%s>\n%s\n</style>\n",
     340            "<style id='%s-inline-css'>\n%s\n</style>\n",
    369341            esc_attr( $handle ),
    370             $this->type_attr,
    371342            $output
    372343        );
Note: See TracChangeset for help on using the changeset viewer.