Search code examples
csswordpresswordpress-gutenberg

WordPress Gutenberg handling CSS in the editor


I've created my website that compiles my scss (boostrap, node_modules, my own custom css) to a single file. Now I'm wondering what would be the best way of styling gutenberg blocks in the editor?

I want to keep the responsive nature of my blocks from bootstrap and my styling what would be the best approach to do this?


Solution

  • If I'm understanding correctly, you want the CSS file for the front-end of your site to also apply to the block editor?

    If so, that's as simple as adding add_theme_support('editor-styles'); in your theme files (such as in functions.php).

    I find it helpful to create a second block-editor stylesheet to use only in the editor. Sometimes I find the media query breakpoints are too different or just need to tweak the front-end styles a little for the editor. For that file, you can use wp_enqueue_script() on the enqueue_block_editor_assets action hook so it applies only to the editor.