Render block somewhere else in PHP
-
I want to hide my block-lab block from the page content and show it in the header. How do I render the block in header.php?
In my header.php I have:
<?php get_hero_banner($post->post_content) ?>In functions.php my problem is render_block_core_block
function get_hero_banner($content){ $blocks = parse_blocks( $content ); $content = ''; foreach ($blocks as $block) { if ($block['blockName'] == 'block-lab/hero') { $attributes = (array) $block['attrs']; $render = render_block_core_block( $attributes ); $content .= $render; } } if ($content == '') { $content = '<p>Missing block</p>'; } return $content; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Render block somewhere else in PHP’ is closed to new replies.