Inline style on rendered content #2255
Replies: 1 comment 3 replies
-
Thank you so much! this has helped solve a huge problem we have been trying to solve. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much! this has helped solve a huge problem we have been trying to solve. |
Beta Was this translation helpful? Give feedback.
-
Gutenberg will enqueue inline styling on posts. If you query the content directly (via WP_GraphQL, for example), these styles get lost.
https://github.com/WordPress/WordPress/blob/master/wp-includes/block-supports/layout.php#L178
One approach to solving this is to just rebuild the content and return the styling with the string, using
wp_render_layout_support_flag
I created a gist with an example: https://gist.github.com/KevinBatdorf/daec9345115279f1c9fe49deb589882f
There may be other (better) approaches, but one way is to modify the function to return the styling with the content. One caveat is that the
render_block
filter is run after other filters have been applied, so you may miss out on something if you're using other pre render filters.Another approach would be to use
wp_get_layout_style
and parse the block first for the container name and layout. I haven't attempted this as the above works for me so far. I'll update if any new developments appear.Beta Was this translation helpful? Give feedback.
All reactions