do_blocks and missing inner html content
- This topic has 7 replies, 2 voices, and was last updated 2 years, 8 months ago by
Nicholas Cox.
-
AuthorPosts
-
March 31, 2023 at 3:51 AM #41275
Nicholas Cox
ParticipantHi
I am trying to output a block using do_blocks($blockcontent) https://developer.wordpress.org/reference/functions/do_blocks/
and the output does not include the innerHTML content, do you know why this is? I ask as the core blocks successfully output the innerHTML.Thanks
e.g. of $blockcontent
<!-- wp:meta-box/dc-favourite-button-block {"id":"mb-block-0634ff4f-9fee-4024-a2b6-6c29dd19e46b","data":{"button_text":"\u0026#x2764;","button_text_colour":"#1e73be","button_text_colour_active":"#8224e3","favourite_type":"product","favourite_database_check":1,"default_favourite_value":0}} /-->April 1, 2023 at 5:14 PM #41285Peter
ModeratorHello,
Thank you for your feedback.
I'm checking the issue and get back to you later.
April 2, 2023 at 5:42 PM #41297Nicholas Cox
Participantthanks, just wanted to render out the blocks for a custom app using the rest api.
April 2, 2023 at 9:12 PM #41299Peter
ModeratorHello,
What do you mean the innerHTML content in your case? It depends on the template that you use to output the custom block on your site. Or do you mean the inner blocks? I see the function
do_blocks()also renders the inner blocks as well.April 2, 2023 at 9:29 PM #41300Nicholas Cox
ParticipantHi, I just want to render the block html on the front end of my site using my theme template using do_blocks()
April 3, 2023 at 12:26 AM #41301Nicholas Cox
ParticipantSo take the following block html block code and output the html.
<!-- wp:meta-box/dc-favourite-button-block {"id":"mb-block-0634ff4f-9fee-4024-a2b6-6c29dd19e46b","data":{"button_text":"\u0026#x2764;","button_text_colour":"#1e73be","button_text_colour_active":"#8224e3","favourite_type":"product","favourite_database_check":1,"default_favourite_value":0}} /-->April 3, 2023 at 6:35 PM #41307Peter
ModeratorHello,
Can you please share a screenshot or the code that you use to render the block? Here is an example on my demo site:
$content = '<!-- wp:meta-box/block-meta {"id":"mb-block-013da68d-63fa-4783-be27-126100bac665","data":{"first_name1":"Meta Box"}} --> <!-- wp:heading --> <h2 class="wp-block-heading">This is the heading text</h2> <!-- /wp:heading --> <!-- /wp:meta-box/block-meta -->'; echo do_blocks( $content );Code to render the block https://monosnap.com/file/N8eBWEtGhkpcvya5Ot8Sv28GfOxnWA
what it displays on the frontend https://monosnap.com/file/zcEfNCjiRuqIMZGAhjk7sD3c5m79FrApril 4, 2023 at 11:37 PM #41341Nicholas Cox
ParticipantHi,
thanks for the example, i have resolved my issue, it turns out there was nothing wrong with the code, i was running it too early inside my custom plugin, this returned a empty value, my bad.
sorry to have wasted your time.
-
AuthorPosts
- You must be logged in to reply to this topic.