How to load block assets in php templates if using hybrid theme

Hi @dahliasan,

This two functions do the same thing, block_header_area call the function block_template_part which call the function do_blocks

function block_header_area() {
block_template_part( 'header' );
}
function block_template_part( $part ) {
$template_part = get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' );
if ( ! $template_part || empty( $template_part->content ) ) {
return;
}
echo do_blocks( $template_part->content );
}

Sorry, I should have elaborated a little. I haven’t tried, but I think something like this should work :

<html>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<?php
$block_header_part = get_block_template( get_stylesheet() . '//header', 'wp_template_part' );
$block_header = $block_header_part && ! empty( $block_header_part->content ) ? do_blocks( $block_header_part->content ) : '';
$block_content = do_blocks( '
<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:post-content /-->
</div>
<!-- /wp:group -->'
);
?>
<?php wp_head(); ?>
</head>
<body>
<?php
echo $block_header;
echo $block_content;
?>
</body>
</html>

Can you test that and tell me if it’s work ?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer