Created
August 11, 2012 12:59
-
-
Save diasbruno/3324324 to your computer and use it in GitHub Desktop.
Load fonts from google fonts CDN.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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