WordPress filter hook · part of WordPress core
style_loader_tag
A WordPress core filter that 4 plugins also fire themselves, running on 500K+ sites between them.
“Filter the stylesheet tag. For example: making it deferred when using Critical CSS.”
How to use style_loader_tag
It's a filter: your callback receives the value and 3 more arguments, and must return the (changed) value.
Add this to your theme's functions.php or a small custom plugin:
add_filter( 'style_loader_tag', function( $tag, $handles, $href, $media ) {
// Change $tag here.
return $tag;
}, 10, 4 );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 →
4 plugins that fire style_loader_tag
Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.
-
Page Optimize300,000+ installs
apply_filters( 'style_loader_tag', $tag, $handles[0], $href, $media )concat-css.php:330 -
Jetpack Boost200,000+ installs
apply_filters( 'style_loader_tag', $style_tag, implode( ',', $handles ), $href, $media )app/lib/minify/class-concatenate-css.php:250 -
AdFever for WordPress10+ installs
apply_filters( 'style_loader_tag', "<link rel='stylesheet' href='$href' type='text/css' media='$media' />\n", $handle )lib/wp-compat/class.wp-styles.php:49 -
SOptimizerFewer than 10 installs
apply_filters( 'style_loader_tag', $style_tag, implode( ',', $handles ), $cache_url, $media )includes/class-siskopfowo-minify-combine.php:459
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.