Created
September 13, 2015 17:14
-
-
Save pingram3541/f7d78167c91e5b50a548 to your computer and use it in GitHub Desktop.
BeTheme - Google font shortcode - line-height option
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
/* --------------------------------------------------------------------------- | |
* Google Font [google_font] | |
* --------------------------------------------------------------------------- */ | |
if( ! function_exists( 'sc_google_font' ) ) | |
{ | |
function sc_google_font( $attr, $content = null ) | |
{ | |
extract(shortcode_atts(array( | |
'font' => '', | |
'size' => '25', | |
'line_height' => '25', | |
'weight' => '400', | |
'italic' => '', | |
'color' => '', | |
'subset' => '', | |
), $attr)); | |
// style | |
$style = array(); | |
$style[] = "font-family:'". $font ."',Arial,Tahoma,sans-serif;"; | |
$style[] = "font-size:". $size ."px;"; | |
if(!empty($line_height)){ | |
$style[] = "line-height:". $line_height ."px;"; | |
} else { | |
$style[] = "line-height:". $size ."px;"; | |
} | |
$style[] = "font-weight:". $weight .";"; | |
if( $color ) $style[] = "color:". $color .";"; | |
// italic | |
if( $italic ){ | |
$style[] = "font-style:italic;"; | |
$weight = $weight .'italic'; | |
} | |
$style = implode( ' ', $style ); | |
// slug | |
$font_slug = str_replace(' ', '+', $font); | |
// subset | |
if( $subset ){ | |
$subset = '&subset='. str_replace(' ', '', $subset); | |
} else { | |
$subset = false; | |
} | |
$output = '<link type="text/css" rel="stylesheet" href="http'. mfn_ssl() .'://fonts.googleapis.com/css?family='. $font_slug .':'. $weight . $subset .'">'."\n"; | |
$output .= '<div class="google_font" style="'. $style .'">'. do_shortcode($content) .'</div>'."\n"; | |
return $output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment