-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
Hi! I'm making a theme that uses the typography field and found that I needed to write a simple font-end compiler
Below is a sample function that grabs all unique font families from all options pages and then calls them on the front end.
function anf_load_custom_fonts ( ) {
$fields = get_field_objects('option'); // or whatever custom post, id, etc.
$font_scraper = array();
// Grab each unique instance of a custom font
foreach ($fields as $key => $value) {
if ( $value['type'] == 'typography' ) {
$family = $value['value']['font-family'];
if ( !array_search($family, $font_scraper))
$font_scraper[$key] = $family;
}
}
// create a string
foreach ($font_scraper as $font) {
$fonts = implode("|", $font_scraper);
}
// enqueue the necessary fonts
if ( $fonts ) {
wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=' . $fonts, array(), NULL, false );
}
}Just wondering if there is a way that similar code could be introduced into the plugin. Would be very useful!
Reactions are currently unavailable