Skip to content

Instantly share code, notes, and snippets.

@robneu
Forked from FernE97/typekit-enqueue.php
Last active January 17, 2023 23:04
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robneu/6400399 to your computer and use it in GitHub Desktop.
Save robneu/6400399 to your computer and use it in GitHub Desktop.
Enqueue typekit fonts to WordPress using wp_enqueue_scripts.
<?php
/**
* Enqueue typekit fonts into WordPress using wp_enqueue_scripts.
*
* @author Robert Neu
* @author Eric Fernandez
* @copyright Copyright (c) 2014, Robert Neu
* @license GPL-2.0+
* @link http://typekit.com
*/
add_action( 'wp_enqueue_scripts', 'prefix_enqueue_scripts' );
/**
* Loads the main typekit Javascript. Replace your-id-here with the script name
* provided in your Kit Editor.
*
* @todo Replace prefix with your theme or plugin prefix
*/
function prefix_enqueue_scripts() {
wp_enqueue_script( 'typekit', '//use.typekit.net/your-id-here.js', array(), '1.0.0' );
}
add_action( 'wp_head', 'prefix_typekit_inline' );
/**
* Check to make sure the main script has been enqueued and then load the typekit
* inline script.
*
* @todo Replace prefix with your theme or plugin prefix
*/
function prefix_typekit_inline() {
if ( wp_script_is( 'typekit', 'enqueued' ) ) {
echo '<script type="text/javascript">try{Typekit.load();}catch(e){}</script>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment