Skip to content

Instantly share code, notes, and snippets.

@tomfinitely
Created March 3, 2026 17:50
Show Gist options
  • Select an option

  • Save tomfinitely/ce4e67c53175065a44791c0dd6c84e6c to your computer and use it in GitHub Desktop.

Select an option

Save tomfinitely/ce4e67c53175065a44791c0dd6c84e6c to your computer and use it in GitHub Desktop.
Preconnect Adobe Fonts in WordPress
<?php
//Async CSS
add_filter('style_loader_tag', 'add_stylesheet_attributes', 10, 2);
function add_stylesheet_attributes($html, $handle)
{
$styles = array(
'fonts',
'adobe-fonts',
);
if (in_array($handle, $styles)) {
return str_replace("rel='stylesheet'", "rel='stylesheet' media='print' onload='this.media=\"all\"'", $html);
}
return $html;
}
//Preload resources
function enqueue_external_fonts() {
// Enqueue the Adobe Fonts stylesheet.
wp_enqueue_style(
'adobe-fonts',
'https://use.typekit.net/mtm0yqs.css',
array(),
null
);
// Instruct WordPress to output a preload <link> for this style.
wp_style_add_data( 'adobe-fonts', 'preload', true );
}
add_action( 'enqueue_block_assets', 'enqueue_external_fonts' );
function preconnect_adobe_fonts( $urls, $relation_type ) {
if ( 'preconnect' === $relation_type && wp_style_is( 'adobe-fonts', 'queue' ) ) {
$urls[] = array(
'href' => 'https://use.typekit.net',
'crossorigin' => 'anonymous',
);
}
return $urls;
}
add_filter( 'wp_resource_hints', 'preconnect_adobe_fonts', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment