Skip to content

Instantly share code, notes, and snippets.

@sarahmonster
Created August 22, 2016 13:25
Show Gist options
  • Save sarahmonster/f2c8d36602cd8b0102d5e5d2126a7e41 to your computer and use it in GitHub Desktop.
Save sarahmonster/f2c8d36602cd8b0102d5e5d2126a7e41 to your computer and use it in GitHub Desktop.
Enqueue Typekit fonts for better local development.
/**
* Enqueue Typekit fonts for local development.
*
* @action wp_head
* @return string
*/
function themeslug_local_fonts() {
if ( 'http://themeslug.dev' === site_url() ):
$kit = '#######';
?>
<script>
// try{!function(t,e,n,r,a,s,i,l)
</script>
<script>
(function(d) {
var config = {
kitId: '<?php echo $kit; ?>',
scriptTimeout: 3000
},
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='https://use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
})(document);
</script>
<?php
endif;
}
add_action( 'wp_head', 'themeslug_local_fonts', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment