Use Google Fonts in Theme and Plugin Settings Pages

You can use TK Google Fonts in your themes and plugin admin setting pages. All Google Fonts are stored in an option array in the options table.

Get the Google Fonts

Get the options with the Google Fonts Array

$tk_google_fonts_options = get_option('tk_google_fonts_options'); 

The Option Array

The Array structure looks like this:

    

Array
(
[selected_fonts]    => Array
(
    [Aclonica]                                        => Aclonica
    [Annie+Use+Your+Telescope        => Annie+Use+Your+Telescope
    [Anonymous+Pro]                            => Anonymous+Pro
)
)

Add a Google Font Select to your Theme and Plugin Settings

   

echo'<select name="name">';
if(isset($tk_google_fonts_options['selected_fonts'])){
        foreach ($tk_google_fonts_options['selected_fonts'] as $key => $google_font) {
echo'<option value="'. $key .'">'. $google_font .'</option>';
        }
}
echo'</select>';

Prepare the Font Names to work in CSS

To use the font names in your CSS you need to change the $google_font value from '+' to ' '

if(isset($tk_google_fonts_options['selected_fonts'])){
    foreach ($tk_google_fonts_options['selected_fonts'] as $key => $x2google_font) {
        $tk_google_fonts_options['selected_fonts'][$key] = str_replace("+"," ", $x2google_font);
    }

}

Still need help? Contact Us Contact Us