Skip to content

Instantly share code, notes, and snippets.

@thomasgriffin
Created December 27, 2014 00:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save thomasgriffin/ca6b461de1bb4b796a0e to your computer and use it in GitHub Desktop.
Save thomasgriffin/ca6b461de1bb4b796a0e to your computer and use it in GitHub Desktop.
Load a TypeKit Font Kit inside of the TinyMCE Visual Editor in WordPress.
(function() {
tinymce.create('tinymce.plugins.typekit', {
init: function(ed, url) {
ed.onPreInit.add(function(ed) {
// Get the iframe.
var doc = ed.getDoc();
// Create the script to inject into the header asynchronously.
var jscript = "(function() {
var config = {
kitId: 'gcc4mmp' // YOUR TYPEKIT ID GOES HERE INSIDE THE SINGLE QUOTES.
};
var d = false,
tk = document.createElement('script');
tk.src = '//use.typekit.net/' + config.kitId + '.js';
tk.type = 'text/javascript';
tk.async = 'true';
tk.onload = tk.onreadystatechange = function() {
var rs = this.readyState;
if (d || rs && rs != 'complete' && rs != 'loaded') return;
d = true;
try { Typekit.load(config); } catch (e) {}
};
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(tk, s);
})();";
// Create a DOM script element and insert the code inside of it.
var script = doc.createElement("script");
script.type = "text/javascript";
script.appendChild(doc.createTextNode(jscript));
// Append the srcript to the header.
doc.getElementsByTagName('head')[0].appendChild(script);
});
},
getInfo: function() {
return {
longname: 'TypeKit',
author: 'Thomas Griffin',
authorurl: 'https://thomasgriffin.io',
infourl: 'https://twitter.com/jthomasgriffin',
version: '1.0'
};
}
});
tinymce.PluginManager.add('typekit', tinymce.plugins.typekit);
})();
@murum
Copy link

murum commented Jul 6, 2017

You just solved my biggest issue ever occured! Big thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment