Skip to content

Instantly share code, notes, and snippets.

@cristianstan
Last active August 5, 2021 02:19
Show Gist options
  • Select an option

  • Save cristianstan/5e771db0eb147a6bc8a6e9b0ef22709e to your computer and use it in GitHub Desktop.

Select an option

Save cristianstan/5e771db0eb147a6bc8a6e9b0ef22709e to your computer and use it in GitHub Desktop.
ThemeForest HowTo: GET GOOGLE FONTS FROM THEME OPTIONS PANEL (REDUX PANEL)
<?php
/* FUNCTION: GET GOOGLE FONTS FROM THEME OPTIONS PANEL (REDUX PANEL) */
function themename_get_site_fonts(){
global $themename_redux;
$fonts_string = '';
if (isset($themename_redux['google-fonts-select'])) {
$i = 0;
$len = count($themename_redux['google-fonts-select']);
foreach(array_keys($themename_redux['google-fonts-select']) as $key){
$font_url = str_replace(' ', '+', $themename_redux['google-fonts-select'][$key]);
if ($i == $len - 1) {
// last
$fonts_string .= $font_url;
}else{
$fonts_string .= $font_url . '|';
}
$i++;
}
// fonts url
$fonts_url = add_query_arg( 'family', $fonts_string, "//fonts.googleapis.com/css" );
// enqueue fonts
wp_enqueue_style( 'themename-fonts', $fonts_url, array(), '1.0.0' );
}
}
add_action('wp_enqueue_scripts', 'themename_get_site_fonts');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment