Skip to content

Instantly share code, notes, and snippets.

@robincornett
Created October 14, 2019 20:24
Show Gist options
  • Save robincornett/50a23dfa2b750409d58e337755f12ef4 to your computer and use it in GitHub Desktop.
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.
<?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