Skip to content

Instantly share code, notes, and snippets.

@diasbruno
Created August 11, 2012 12:59
Show Gist options
  • Save diasbruno/3324324 to your computer and use it in GitHub Desktop.
Save diasbruno/3324324 to your computer and use it in GitHub Desktop.
Load fonts from google fonts CDN.
/**
* Load fonts from google fonts CDN.
* @param $fonts {Array} Array of fonts to be loaded.
* @param $echo {Boolean} If true, print each <link>, else, return an array
* @return {Array} If $echo is true, it will return an empty string.
* @example loadFontFromGoogle( array(
* "Open Sans" => "300,400,600" // font name => thickness
* ));
*/
function loadFontFromGoogle( $fonts, $echo = true ) {
$listOfFonts = array();
$googlefontsURL = 'http://fonts.googleapis.com/css?family=';
$i = 0;
foreach ($fonts as $key => $value) {
$key = join( '+', explode( ' ', $key ) );
$fontURL = $googlefontsURL.$key.':'.$value;
if ( $echo )
printf( '<link href="%s" rel="stylesheet" type="text/css">', $fontURL );
else
$listOfFonts[ $key ] = '<link href="'.$fontURL.'" rel="stylesheet" type="text/css">';
$i += 1;
}
return $listOfFonts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment