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.
Source
$tag = apply_filters( 'style_loader_tag', $tag, $handle, $href, $media );
This simple change will make your browser call the Google Font page in the applicable mode (HTTP vs HTTPS) with wp_enqueue_style.
To defer loading of non-critical CSS :
If you want to harden your website against supply chain attacks, you can use this filter to add Subresource integrity checking to an enqueued style.
For example, for Select2 style v4.0.9 from cdnjs.com, you would copy the SRI hash from https://cdnjs.com/libraries/select2/4.0.9, and add it as an attribute to the style. Then check for the select2 handle and that it’s a link, before adding the SRI attributes.
This function uses the WP_HTML_Tag_Processor class introduced in WordPress 6.2.
You can add SRI to an enqueued script in a similar way: https://developer.wordpress.org/reference/hooks/wp_script_attributes/#comment-6783