Created
October 14, 2019 20:24
-
-
Save robincornett/50a23dfa2b750409d58e337755f12ef4 to your computer and use it in GitHub Desktop.
Add custom editor font sizes to your site after the block library styles using wp_inline_style.
This file contains 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_action( 'enqueue_block_assets', 'rgc_editor_font_sizes', 15 ); | |
/** | |
* Add custom font sizes to the site using wp_inline_style, attached to the wp-block-library stylesheet. | |
* Editor font sizes must be defined in your theme. | |
*/ | |
function rgc_editor_font_sizes() { | |
list( $font_sizes, ) = (array) get_theme_support( 'editor-font-sizes' ); | |
if ( ! $font_sizes ) { | |
return; | |
} | |
$css = ''; | |
foreach ( $font_sizes as $size ) { | |
$css .= sprintf( '.has-%s-font-size {font-size: %spx;}', $size['slug'], $size['size'] ); | |
} | |
wp_add_inline_style( 'wp-block-library', $css ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment