I have several Gutenberg blocks. I'd like them not to show up together in frontend inside the_content. I'd like to use them for other purposes, so I would need to query them (get their contents) one by one, store in memory and then place them where I want. Is it possible? Can't find docs about.
I have several Gutenberg blocks. I'd like them not to show up together in frontend inside the_content. I'd like to use them for other purposes, so I would need to query them (get their contents) one by one, store in memory and then place them where I want. Is it possible? Can't find docs about.
My own answer is: somewhat yes, but not so easily. We can use 2 functions:
https://developer.wordpress/reference/functions/parse_blocks/
https://developer.wordpress/reference/functions/render_block/
Not very well documented yet. But you can pass raw content to parse_blocks to have them back in array form.
The thing is that they don't have some sort of ID. So this approach is not always usefult, depending on what you want to do with them.