Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#22245 closed feature request (duplicate)

Add Hook: "script_loader_tag"

Reported by: ryanve's profile ryanve Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

There exists a filter for "style_loader_tag" in wp-includes/class.wp-styles.php. A corresponding filter "script_loader_tag" in wp-includes/class.wp-scripts.php would be very useful for customizing script loading.

Change History (5)

#1 @scribu
12 years ago

Example use case?

#2 @ryanve
12 years ago

add_filter( 'script_loader_tag', function ( $html, $handle ) {
    if ( 'example' !== $handle )
        return $html;
    return str_replace( '<script ', '<script async ', $html );
}, 12, 2);
Last edited 12 years ago by ryanve (previous) (diff)

#3 @ocean90
12 years ago

  • Component changed from Formatting to General
  • Keywords dev-feedback needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #13592.

#4 @ryanve
12 years ago

@ocean90 There's no explanation in #13592 as to why "script_loader_tag" was not added.

#5 @ryanve
12 years ago

@scribu another potential use case is wrapping a script in IE conditionals (see #16024)

add_filter( 'script_loader_tag', function ( $html, $handle ) {
    return 'html5-shim' === $handle' ? <!--[if lt IE 9]>' . $html . '<![endif]-->' : $html;
}, 12, 2);
Note: See TracTickets for help on using tickets.