I am taking the Udemy WordPress course to create a custom WordPress block theme. I successfully registered the block type in function.php and can select my block in the Gutenberg editor.
The tutorial suggested using the following method to load the styles for my gutenberg block element so that the css is also loaded on the frontend.
function lr_theme_features() { // Enqueue editor styles // Borrowed from TwentyTwentyToTheme add_editor_style( 'style.css' ); add_theme_support('editor-styles'); } add_action('after_setup_theme', 'lr_theme_features');
Anyway, no matter what I do, Gutenberg won't load my block's style.css file.
Image from Gutenberg backend
Any tips? What might I be missing or how can I debug the problem?
Thank you so much!
I'm also having some issues with my admin CSS. I found that if you import CSS in admin style.css like this, it breaks style loading:
Strangely, it works without quotes, like this:
But not sure if this is a good practice... The best practice is to load external libraries like this instead of using import statements:
Hope it helps others!
Inblock-based themes,
wp-block-styles
is used to load stylesheets in the editor and frontend.TwentyTwentyTwoThe theme uses the same technology; given that block-based themes are relatively new, you may have followed a (now) outdated theme tutorial.If you still don't see the styles loading, check that the class name of the block you're targeting matches the HTML tag.
PS. Always clear your browser cache/hard refreshto ensure you are not seeing a cached version of your editor - this is a very common but overlooked cause of many problems.