2

In the block editor for posts and pages, I used to use the enqueue_block_editor_assets hook to enqueue styles for the block.

add_action( 'enqueue_block_editor_assets','load_assets_in_block' );
function load_assets_in_block() {
            wp_enqueue_style(
                'block-style',
                plugins_url( 'assets/css/block-style.css', PLAYER_PLUGIN ),
                array(),
                PLAYER_PLUGIN_VERSION,
                false
            );
}

This still works on posts and pages block, but it isn't working on the new site editor in WordPress 5.9? What is the recommended way to enqueue styles in site editor?

1
  • I am having this same issue too. In the site editor, the styles load but all of the blocks are loaded inside an iframe where the styles are not loaded. So they are not applied to the blocks and they are unstyled. I have a feeling this is an issue in Wordpress more than anything.
    – JoeMoe1984
    Mar 30, 2022 at 18:09

1 Answer 1

1

So apparently for the site editor, you need to add the styles a little bit differently. You need to use the add_editor_style function.

add_action('after_setup_theme', 'my_add_editor_styles_to_full_site_editing');

function my_add_editor_styles_to_full_site_editing()
{
    add_theme_support('editor-styles');
    add_editor_style('site-editor.css');
}

Becareful how you style your stylesheet

This function adds your styles inline wrapped in the .editor-styles-wrapper class.

1
  • Just a heads-up: since 5.9, add_theme_support( 'editor-styles' ); are included by default for block themes, so it's unnecessary for this type of theme (source). Aug 25, 2022 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.