Make WordPress Core


Ignore:
Timestamp:
09/18/2019 02:49:30 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Script Loader: Introduce HTML5 support for scripts and styles.

When a theme declares HTML5 support for script and styles via add_theme_support( 'html5', array( 'script', 'style' ) ), the type="text/javascript" and type="text/css" attributes are omitted.

These attributes are unnecessary in HTML5 and cause warnings in the W3C Markup Validation Service.

Props sasiddiqui, swissspidy, knutsp, SergeyBiryukov.
See #42804.

File:
1 edited

Legend:

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

    r45926 r46164  
    703703        return;
    704704    }
    705     echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />';
     705
     706    $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
     707
     708    printf(
     709        '<link rel="stylesheet" href="%s"%s media="screen" />',
     710        $stylesheet,
     711        $type_attr
     712    );
    706713}
    707714
     
    16421649    if ( ! $background && ! $color ) {
    16431650        if ( is_customize_preview() ) {
    1644             echo '<style type="text/css" id="custom-background-css"></style>';
     1651            $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
     1652            printf( '<style%s id="custom-background-css"></style>', $type_attr );
    16451653        }
    16461654        return;
     
    16941702
    16951703        $style .= $image . $position . $size . $repeat . $attachment;
     1704
     1705        $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
    16961706    }
    16971707    ?>
    1698 <style type="text/css" id="custom-background-css">
     1708<style<?php echo $type_attr; ?> id="custom-background-css">
    16991709body.custom-background { <?php echo trim( $style ); ?> }
    17001710</style>
     
    17101720    $styles = wp_get_custom_css();
    17111721    if ( $styles || is_customize_preview() ) :
     1722        $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
    17121723        ?>
    1713         <style type="text/css" id="wp-custom-css">
     1724        <style<?php echo $type_attr; ?> id="wp-custom-css">
    17141725            <?php echo strip_tags( $styles ); // Note that esc_html() cannot be used because `div &gt; span` is not interpreted properly. ?>
    17151726        </style>
     
    23362347 *
    23372348 * @since 2.9.0
    2338  * @since 3.6.0 The `html5` feature was added
    2339  * @since 3.9.0 The `html5` feature now also accepts 'gallery' and 'caption'
    2340  * @since 4.1.0 The `title-tag` feature was added
    2341  * @since 4.5.0 The `customize-selective-refresh-widgets` feature was added
    2342  * @since 4.7.0 The `starter-content` feature was added
     2349 * @since 3.6.0 The `html5` feature was added.
     2350 * @since 3.9.0 The `html5` feature now also accepts 'gallery' and 'caption'.
     2351 * @since 4.1.0 The `title-tag` feature was added.
     2352 * @since 4.5.0 The `customize-selective-refresh-widgets` feature was added.
     2353 * @since 4.7.0 The `starter-content` feature was added.
    23432354 * @since 5.0.0 The `responsive-embeds`, `align-wide`, `dark-editor-style`, `disable-custom-colors`,
    23442355 *              `disable-custom-font-sizes`, `editor-color-palette`, `editor-font-sizes`,
    23452356 *              `editor-styles`, and `wp-block-styles` features were added.
     2357 * @since 5.3.0 The `html5` feature now also accepts 'script' and 'style'.
    23462358 *
    23472359 * @global array $_wp_theme_features
     
    26362648        $classes = '.' . implode( ', .', $classes );
    26372649
     2650        $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
    26382651        ?>
    26392652        <!-- Custom Logo: hide header text -->
    2640         <style id="custom-logo-css" type="text/css">
     2653        <style id="custom-logo-css"<?php echo $type_attr; ?>>
    26412654            <?php echo $classes; ?> {
    26422655                position: absolute;
     
    31973210    $home_origin  = parse_url( home_url() );
    31983211    $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) );
    3199 
     3212    $type_attr    = current_theme_supports( 'html5', 'script' ) ? '' : ' type="text/javascript"';
    32003213    ?>
    32013214    <!--[if lte IE 8]>
    3202         <script type="text/javascript">
     3215        <script<?php echo $type_attr; ?>>
    32033216            document.body.className = document.body.className.replace( /(^|\s)(no-)?customize-support(?=\s|$)/, '' ) + ' no-customize-support';
    32043217        </script>
    32053218    <![endif]-->
    32063219    <!--[if gte IE 9]><!-->
    3207         <script type="text/javascript">
     3220        <script<?php echo $type_attr; ?>>
    32083221            (function() {
    32093222                var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\\s+)(no-)?'+cs+'(\\s+|$)');
Note: See TracChangeset for help on using the changeset viewer.