You appear to be a bot. Output may be restricted
Description
Adds async/defer attributes to enqueued / registered scripts.
If #12009 lands in WordPress, this function can no-op since it would be handled in core.
Usage
$string = TwentyTwenty_Script_Loader::filter_script_loader_tag( $tag, $handle );
Parameters
- $tag
- ( string ) required – The script tag.
- $handle
- ( string ) required – The script handle.
Returns
string Script HTML string.
Source
File name: twentytwenty/classes/class-twentytwenty-script-loader.php
Lines:
1 to 15 of 15
public function filter_script_loader_tag( $tag, $handle ) { foreach ( array( 'async', 'defer' ) as $attr ) { if ( ! wp_scripts()->get_data( $handle, $attr ) ) { continue; } // Prevent adding attribute when already added in #12009. if ( ! preg_match( ":\s$attr(=|>|\s):", $tag ) ) { $tag = preg_replace( ':(?=></script>):', " $attr", $tag, 1 ); } // Only allow async or defer, not both. break; } return $tag; }