html blocks from gutenberg are not styled #262
-
A tailwind component/element that I paste in an html-block doesnt get the tailwind styling. If I paste the same in the theme directly it does get styled. How can I get gutenberg blocks styled? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This is an issue with Tailwind as it uses "JUST IN TIME" method to collect all the classes used and then create the styles for them, if you use the HTML block from Gutenberg that's effectively data not code, tailwind has no idea what classes are there. You can manually add the component as a template-part which tailwind will find or add the classes in the CSS file using @apply |
Beta Was this translation helpful? Give feedback.
-
Here is code for updating safelist.txt. It adds the classes used in the wp editor. It goes into the functions.php file. ` /**
// Only run on posts and pages // Get the post content // Simple regex to extract class names $classes = []; // Remove duplicates and empty classes // Get existing safelist if (file_exists($safelist_path)) { // Merge existing with new classes // Save the updated safelist // Optional: Trigger Tailwind rebuild if needed ` Running npm run watch, it picks up the classes correctly. But how to do this on a production server, or even a server without node/npm installed? |
Beta Was this translation helpful? Give feedback.
This is an issue with Tailwind as it uses "JUST IN TIME" method to collect all the classes used and then create the styles for them, if you use the HTML block from Gutenberg that's effectively data not code, tailwind has no idea what classes are there.
You can manually add the component as a template-part which tailwind will find or add the classes in the CSS file using @apply