Skip to content

Instantly share code, notes, and snippets.

@pingram3541
Created September 13, 2015 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pingram3541/f7d78167c91e5b50a548 to your computer and use it in GitHub Desktop.
Save pingram3541/f7d78167c91e5b50a548 to your computer and use it in GitHub Desktop.
BeTheme - Google font shortcode - line-height option
/* ---------------------------------------------------------------------------
* 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