apply_filters( 'style_loader_tag', string $tag, string $handle, string $href, string $media )

Filters the HTML link tag of an enqueued style.


Parameters

$tag string
The link tag for the enqueued style.
$handle string
The style's registered handle.
$href string
The stylesheet's source URL.
$media string
The stylesheet's media attribute.

Top ↑

Source

File: wp-includes/class-wp-styles.php. View all references

$tag = apply_filters( 'style_loader_tag', $tag, $handle, $href, $media );


Top ↑

Changelog

Changelog
Version Description
4.5.0 Introduced the $media parameter.
4.3.0 Introduced the $href parameter.
2.6.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content

    This simple change will make your browser call the Google Font page in the applicable mode (HTTP vs HTTPS) with wp_enqueue_style.

    add_filter( 'style_loader_tag', 'wpdocs_remove_https_styles', 10, 2 );
    function wpdocs_remove_https_styles( $html, $handle ) {
    	$handles = array( 'twentysixteen-fonts', 'open-sans' );
    	if ( in_array( $handle, $handles ) ) {
    		$html = str_replace( 'https:', '', $html );
    	}
    	return $html;
    }
  2. Skip to note 2 content
    Contributed by Geoffrey Brossard

    To defer loading of non-critical CSS :

    function prefix_defer_css_rel_preload( $html, $handle, $href, $media ) {
        if ( ! is_admin() ) {
            $html = '<link rel="preload" href="' . $href . '" as="style" id="' . $handle . '" media="' . $media . '" onload="this.onload=null;this.rel=\'stylesheet\'">'
                . '<noscript>' . $html . '</noscript>';
        }
        return $html;
    }
    add_filter( 'style_loader_tag', 'prefix_defer_css_rel_preload', 10, 4 );

You must log in before being able to contribute a note or feedback.