Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Imports Google Webfonts and creates a Dropdown to select a font from.
* Google Font Importer
$fonts = "";
$fonts = file_get_contents($fonts, 0, null, null);
$fp = fopen('fonts.txt', 'w');
fwrite($fp, $fonts);
* Google Font Chooser
$path = "/home/kebopowe/public_html/functions/fonts.txt";
//$path = ""; // use this if remote
$request = file_get_contents( $path );
$fonts = json_decode( $request );
<!DOCTYPE html>
<script src=""></script>
<style type="text/css">
select {
border: 1px solid #ddd;
font-size: 18px;
height: 12em;
select optgroup {
select option {
padding: 2px 6px;
<h2>Google Webfonts Selector</h2>
<select id="font-selector" style="font-family: '<?php echo $fonts->items[0]->family; ?>', Arial,​ sans-serif;" size="4" multiple="multiple">
<?php foreach ( $fonts->items as $font ) { ?>
<optgroup style="font-family: '<?php echo $font->family; ?>', Arial,​ sans-serif;" data-src="<?php echo str_replace(' ', '+', $font->family); ?>&text=<?php echo str_replace(' ', '+', $font->family); ?>">
<option value="<?php echo str_replace(' ', '+', $font->family); ?>"><?php echo $font->family; ?></option>
<?php } ?>
$( document ).ready(function() {
setTimeout( function() {
$.each( $("#font-selector optgroup"), function() {
var src = $(this).data( "src" );
$('head').append("<link href='" + src + "' rel='stylesheet' type='text/css'>");
}, 0);
$("#font-selector").change(function() {
var selected = $("#font-selector option:selected").text();
$(this).css( 'font-family', selected );

This comment has been minimized.

Copy link

@clifgriffin clifgriffin commented Feb 28, 2020

Just FYI your Google API key is here for the world to see :-)

Edit: Google actually seems to take a pretty low view of security of this key so maybe never mind. 🤷‍♂️


This comment has been minimized.

Copy link
Owner Author

@PeterBooker PeterBooker commented Mar 1, 2020

I appreciate the heads up Clifton. I no longer have access to the account the key was setup on, so I am not sure there is a constructive action I can take now. If you have any suggestions I am open to them- after 6 years it feels like deleting it would have a minimal effect, but might be the only course I can take?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment