Make WordPress Core


Ignore:
Timestamp:
09/18/2019 02:49:30 PM (6 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/script-loader.php

    r46157 r46164  
    24662466    }
    24672467
    2468     $concat = trim( $wp_scripts->concat, ', ' );
     2468    $concat    = trim( $wp_scripts->concat, ', ' );
     2469    $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'";
    24692470
    24702471    if ( $concat ) {
    24712472        if ( ! empty( $wp_scripts->print_code ) ) {
    2472             echo "\n<script type='text/javascript'>\n";
     2473            echo "\n<script{$type_attr}>\n";
    24732474            echo "/* <![CDATA[ */\n"; // not needed in HTML 5
    24742475            echo $wp_scripts->print_code;
     
    24852486
    24862487        $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}" . $concatenated . '&ver=' . $wp_scripts->default_version;
    2487         echo "<script type='text/javascript' src='" . esc_attr( $src ) . "'></script>\n";
     2488        echo "<script{$type_attr} src='" . esc_attr( $src ) . "'></script>\n";
    24882489    }
    24892490
     
    26472648    }
    26482649
    2649     $concat = trim( $wp_styles->concat, ', ' );
     2650    $concat    = trim( $wp_styles->concat, ', ' );
     2651    $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
    26502652
    26512653    if ( $concat ) {
     
    26612663
    26622664        $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}" . $concatenated . '&ver=' . $ver;
    2663         echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "' type='text/css' media='all' />\n";
     2665        echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "'{$type_attr} media='all' />\n";
    26642666
    26652667        if ( ! empty( $wp_styles->print_code ) ) {
    2666             echo "<style type='text/css'>\n";
     2668            echo "<style{$type_attr}>\n";
    26672669            echo $wp_styles->print_code;
    26682670            echo "\n</style>\n";
Note: See TracChangeset for help on using the changeset viewer.