I’m following a Udemy WordPress Course to create a custom WordPress Block Theme. I successfully registered the block type within my functions.php and can select my Block in the Gutenberg Editor.
The tutorial suggested to use the following ways to load the styles for my gutenberg block element, so the the css will be loaded in the frontend as well.
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 isn’t loading the style.css file for my block.
Image from the Gutenberg Backend
Any Tips, what I might be missing or how I can debug the problem?
Thank you very much!
2
Answers
In a block based theme,
wp-block-styles
is used to load the stylesheet in the Editor and Frontend. The TwentyTwentyTwo Theme uses the same technique; it may be you’ve followed a (now) outdated theme tutorial given block based themes are relatively new.If you still can’t see your styles being loaded, check the class names of the blocks you’re targeting matches the HTML markup.
PS. Always clear your browser cache/hard refresh to be sure you’re not seeing a cached version of the Editor – its a very common but overlooked cause of many issues.
I had some problem with my admin css too.
I found that if you import CSS like this in your admin style.css, it break the style load :
Strangly, it work without quotes, like this :
But not sure if it’s a good practice…
The best practive is too load external libraries like this, instead of use import statement :
Hope it will help someone else!