Last active
August 5, 2021 02:19
-
-
Save cristianstan/5e771db0eb147a6bc8a6e9b0ef22709e to your computer and use it in GitHub Desktop.
ThemeForest HowTo: GET GOOGLE FONTS FROM THEME OPTIONS PANEL (REDUX PANEL)
This file contains hidden or 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
| <?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