WordPress filter hook · part of WordPress core

script_loader_tag

A WordPress core filter that 7 plugins also fire themselves, running on 612K+ sites between them.

“Filters the HTML script tag of an enqueued script A copy of the core filter of the same name. https://developer.wordpress.org/reference/hooks/script_loader_tag/ Because we have a single script, let's apply the `script_loader_tag` filter as core does in `do_item()`. That way, we interfere less with plugin and theme script filtering. For example, without this filter, there is a case where we bloc...”

How to use script_loader_tag

It's a filter: your callback receives the value and 2 more arguments, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'script_loader_tag', function( $probe_tag, $handle, $js_url ) {
	// Change $probe_tag here.
	return $probe_tag;
}, 10, 3 );

Argument names come from Page Optimize's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

This hook is fired by WordPress core too. Official reference on developer.wordpress.org →

7 plugins that fire script_loader_tag

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Page Optimize icon Page Optimize300,000+ installs apply_filters( 'script_loader_tag', $probe_tag, $handle, $js_url ) concat-js.php:80
  2. Jetpack Boost icon Jetpack Boost200,000+ installs apply_filters( 'script_loader_tag', $tag, $js_array['handles'][0], $href ) app/lib/minify/class-concatenate-js.php:328
  3. Asset CleanUp: Page Speed Booster icon Asset CleanUp: Page Speed Booster100,000+ installs apply_filters( 'script_loader_tag', $tag, $handle, $url ) classes/FrontendManagerFrame.php:190
  4. WS Form LITE icon WS Form LITE10,000+ installs apply_filters( 'script_loader_tag', $tag, $handle, '' ) public/class-ws-form-public.php:586
  5. AdFlow icon AdFlow2,000+ installs apply_filters( 'script_loader_tag', Simple_Google_Adsense_Consent::deferred_script($src, $handle . '-js'), $handle, $src ) includes/class-simple-google-adsense-manual-ads.php:842
  6. {eac}Doojigger Simple GTM Extension for WordPress icon {eac}Doojigger Simple GTM Extension for WordPressFewer than 10 installs apply_filters( 'script_loader_tag', $tag, $handle, $src ) Extensions/class.google_tag_manager.extension.php:267
  7. Sentient Forms icon Sentient FormsFewer than 10 installs apply_filters( 'script_loader_tag', $tag, self::ADMIN_ASSET_HANDLE, $src ) includes/admin/class-sentient-forms-realtime-qna-admin-display.php:360

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.