Make WordPress Core


Ignore:
Timestamp:
10/13/2023 05:19:31 PM (15 months ago)
Author:
westonruter
Message:

Script Loader: Enqueue inline style for block template skip link in head instead of footer.

  • Introduce wp_enqueue_block_template_skip_link() to replace the_block_template_skip_link(). Add to wp_enqueue_scripts action instead of wp_footer.
  • Keep inline script for skip link in footer.
  • Restore original the_block_template_skip_link() from 6.3 and move to deprecated.php.
  • Preserve back-compat for unhooking skip-link by removing the_block_template_skip_link from wp_footer action.

Follow-up to [56682] and [56687].

Props sabernhardt, plugindevs, westonruter, spacedmonkey.
Fixes #59505.
See #58775.
See #58664.

File:
1 edited

Legend:

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

    r56748 r56932  
    100100
    101101/**
    102  * Prints the skip-link script & styles.
     102 * Enqueues the skip-link script & styles.
    103103 *
    104104 * @access private
    105  * @since 5.8.0
     105 * @since 6.4.0
    106106 *
    107107 * @global string $_wp_current_template_content
    108108 */
    109 function the_block_template_skip_link() {
     109function wp_enqueue_block_template_skip_link() {
    110110    global $_wp_current_template_content;
     111
     112    // Back-compat for plugins that disable functionality by unhooking this action.
     113    if ( ! has_action( 'wp_footer', 'the_block_template_skip_link' ) ) {
     114        return;
     115    }
     116    remove_action( 'wp_footer', 'the_block_template_skip_link' );
    111117
    112118    // Early exit if not a block theme.
     
    208214    $skip_link_script = wp_remove_surrounding_empty_script_tags( ob_get_clean() );
    209215    $script_handle    = 'wp-block-template-skip-link';
    210     wp_register_script( $script_handle, false );
     216    wp_register_script( $script_handle, false, array(), false, array( 'in_footer' => true ) );
    211217    wp_add_inline_script( $script_handle, $skip_link_script );
    212218    wp_enqueue_script( $script_handle );
Note: See TracChangeset for help on using the changeset viewer.