Skip to content

Instantly share code, notes, and snippets.

@hyptx
Last active August 30, 2016 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hyptx/ba254b41c6e194734f22 to your computer and use it in GitHub Desktop.
Save hyptx/ba254b41c6e194734f22 to your computer and use it in GitHub Desktop.
Add google fonts to TinyMCE
<?php
/* TinyMCE fonts ~~> */
function ter_mce_google_fonts_array($initArray){
$theme_advanced_fonts .= 'Arimo=Arimo;';
$theme_advanced_fonts .= 'Fredoka One=Fredoka One;';
$theme_advanced_fonts .= 'Oswald=Oswald;';
$initArray['font_formats'] = $theme_advanced_fonts;
$initArray['font_formats'] .= 'Lato=Lato;Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats;';
return $initArray;
}
add_filter('tiny_mce_before_init','ter_mce_google_fonts_array');
function ter_mce_google_fonts_styles(){
$font1 = 'http://fonts.googleapis.com/css?family=Oswald';
add_editor_style( str_replace( ',', '%2C', $font1 ) );
$font2 = 'http://fonts.googleapis.com/css?family=Fredoka+One';
add_editor_style( str_replace( ',', '%2C', $font2 ) );
$font3 = 'http://fonts.googleapis.com/css?family=Arimo:400,700,400italic';
add_editor_style( str_replace( ',', '%2C', $font3 ) );
}
add_action( 'admin_init', 'ter_mce_google_fonts_styles' );
function ter_mce_font_family_dropdown_fonts(){
echo '<link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald">';
echo '<link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Fredoka+One">';
echo '<link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Arimo:400,700,400italic">';
}
add_action('admin_head','ter_mce_font_family_dropdown_fonts');
function schema_TinyMCE_init($in)
{
/**
* Edit extended_valid_elements as needed. For syntax, see
* http://www.tinymce.com/wiki.php/Configuration:valid_elements
*
* NOTE: Adding an element to extended_valid_elements will cause TinyMCE to ignore
* default attributes for that element.
* Eg. a[title] would remove href unless included in new rule: a[title|href]
*/
if(!empty($in['extended_valid_elements']))
$in['extended_valid_elements'] .= ',';
$in['extended_valid_elements'] .= '@[id|class|style|title|itemscope|itemtype|itemprop|datetime|rel],div,dl,ul,dt,dd,li,span,a|rev|charset|href|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur]';
return $in;
}
add_filter('tiny_mce_before_init', 'schema_TinyMCE_init' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment