Enque Typekit Fonts – Not Found

I’m trying to enqueue a typekit on my WP site in a function using code below:

/**
 * TypeKit Fonts
 *
 * @since Theme 1.0
 */
function theme_typekit() {
    wp_enqueue_script( 'theme_typekit', '//use.typekit.net/xxxxxxx.js');
}
add_action( 'wp_enqueue_scripts', 'theme_typekit' );

function theme_typekit_inline() {
  if ( wp_script_is( 'theme_typekit', 'done' ) ) { ?>
    <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
<?php }
}
add_action( 'wp_head', 'theme_typekit_inline' );

Code appears to be working fine, however when url called on frontend it’s showing 404 in console for link, https://use.typekit.net/xxxxxxx.js

Any idea why not found? Note, I’m using a valid typekit code on my end.

1 Answer
1

As mentioned in the comments, your code snippet is working fine. Nevertheless the font kit has to be published within the Kit Editor:

  1. Login to your Typekit account
  2. Locate the Kit Editor (see: https://typekit.com/kit_editor/kits/xxxxxxx)
  3. Click the Publish button (bottom right)

You may also consider using the new embed code provided by Typekit:

<script>try{Typekit.load({ async: true });}catch(e){}</script>

Leave a Comment