Last active
July 20, 2023 13:54
-
-
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
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 | |
| 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