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.
Share Improve this question asked Jan 29, 2019 at 10:54 Luca ReghellinLuca Reghellin 1,6522 gold badges21 silver badges45 bronze badges 1- i guess, if you use your custom blocks with dynamic rendering over the default JS saving, you're a step near your goal.. wordpress/gutenberg/handbook/designers-developers/… – André Kelling Commented Jan 29, 2019 at 11:15
1 Answer
Reset to default 1My 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.