Fragmented Thought

Use TypeKit in a Drupal 7 Theme

By

Published:

Lance Gliser

Heads up! This content is more than six months old. Take some time to verify everything still works as expected.

One of the new themes we rigged up for a client requires the use of TypeKit. The easiest way I found to add the JS they provide is to just add it to the template.php file in hook_preprocess_page. The function drupal_add_js() will allow for external js files, as well as inline scripts. Use the code below, and if external js caching is turned on, it should pick that up while still providing the dynamic fire call you need. Just make sure you update the third parameter on the second function to be some region in your theme. The drupal semi default page_bottom is a pretty safe call. You have to aim to theme it out by altering html.tpl.php.

Could it be a module, yes. Is it worth the effort? No.

function {hook}_preprocess_page(){ // Include typekit drupal_add_js('http://use.typekit.com/agq####dev.js', 'external'); drupal_add_js('try{Typekit.load();}catch(e){}', 'inline', 'page_bottom'); }