Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save michaelwilhelmsen/23e741a9fdd28e5888f89432facb0045 to your computer and use it in GitHub Desktop.

Select an option

Save michaelwilhelmsen/23e741a9fdd28e5888f89432facb0045 to your computer and use it in GitHub Desktop.
A good use for this is when you need more granular control of font sizes in ACF Blocks within repeaters and flexible fields. Instead of using the default Gutenberg font size attribute, you can dynamically load all the font sizes defined by your theme in theme.json
<?php
add_filter('acf/load_field/name=font_size_gutenberg', 'sp_acf_dynamic_fontsizes_load');
function sp_acf_dynamic_fontsizes_load($field) {
// get array of colors created using editor-color-palette
$font_sizes = wp_get_global_settings()['typography']['fontSizes']['theme'];
// if this array is empty, continue
if (!empty($font_sizes)) {
// loop over each color and create option
foreach ($font_sizes as $font_size) {
$field['choices'][$font_size['slug']] = $font_size['name'];
}
}
return $field;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment