Enqueue child theme stylesheet (and Customizer CSS) in block editor

What the title says – this snippet will enqueue your child theme’s stylesheet into the block editor so you can preview changes in real time.

add_filter('generate_editor_styles', function($editor_styles) {
    $editor_styles[] = '/style.css';
    return $editor_styles;
}, 50);

Credit: Alvind with GeneratePress support.

This next snippet will also enqueue your CSS from “Additional CSS” in the Customizer. (credit GP site)

add_filter( 'block_editor_settings_all', function( $editor_settings ) {
    $css = wp_get_custom_css_post()->post_content;
    $editor_settings['styles'][] = array( 'css' => $css );

    return $editor_settings;
} );

1 thought on “Enqueue child theme stylesheet (and Customizer CSS) in block editor”

Leave a Reply to Sam Cancel reply