Make WordPress Core

Changeset 56569


Ignore:
Timestamp:
09/13/2023 10:14:15 PM (9 months ago)
Author:
westonruter
Message:

Bundled Themes: Ensure Twenty Twenty's main script loads in head for WP<6.3.

Amends [56556].
Props westonruter, flixos90, peterwilsoncc.
Fixes #59316.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwenty/functions.php

    r56556 r56569  
    216216    }
    217217
    218     wp_enqueue_script(
    219         'twentytwenty-js',
    220         get_template_directory_uri() . '/assets/js/index.js',
    221         array(),
    222         $theme_version,
    223         array(
    224             'in_footer' => false, // Because involves header.
    225             'strategy'  => 'defer',
    226         )
    227     );
     218    /*
     219     * This script is intentionally printed in the head because it involves the page header. The `defer` script loading
     220     * strategy ensures that it does not block rendering; being in the head it will start loading earlier so that it
     221     * will execute sooner once the DOM has loaded. The $args array is not used here to avoid unintentional footer
     222     * placement in WP<6.3; the wp_script_add_data() call is used instead.
     223     */
     224    wp_enqueue_script( 'twentytwenty-js', get_template_directory_uri() . '/assets/js/index.js', array(), $theme_version );
     225    wp_script_add_data( 'twentytwenty-js', 'strategy', 'defer' );
    228226}
    229227
Note: See TracChangeset for help on using the changeset viewer.