Search code examples
phpcsswordpresswordpress-gutenberg

Apply WordPress customizer styles to Gutenberg editor


I have numerous customizer styles in my WordPress theme, and I'm looking at applying those chosen styles (eg, font colour) to the Gutenberg blocks - editor view.

The customizer styles are pulled through to the front-end using: <?php echo get_theme_mod( 'text_colour', '#222222' ); ?>;

I am using a .css file to apply styles to the block editor, but how do I convert the get_theme_mod into a css style?

Any help would be much appreciated :)


Solution

  • you can use wp_add_inline_style() on the post edit screen!?

    function my_dynamic_editor_styles()
    {
        wp_register_style( 'dummy-handle', false );
        wp_enqueue_style( 'dummy-handle' );
        wp_add_inline_style( 'dummy-handle', '* { color: '.get_theme_mod( 'text_colour', '#222222' ).'; }' );
    }
    
    add_action( 'enqueue_block_editor_assets', 'my_dynamic_editor_styles', 100 );