Posts page content blocks not rendering block styles

I’ve created a page and added some ACF blocks I’ve created. For some reason the styles are not being rendered with the block when I get the posts page ID and the content from it. If I remove it from the posts page setting, the blocks render fine (with styles).

Can anybody assist with the code that would be required to get a specific page’s content and render the blocks on the page with the style as well?

Here is one example that I have tried. Any help would be greatly appreciated.

@php
      $post = get_post(11);
@endphp

{!! do_blocks($post->post_content) !!}

Your issue appears to match well with this one in Gutenberg:

1 Like

Yeah it looks like blocks that do their own styles have an assumption that they’ll run before wp_head() so they can insert styles there. On a normal theme, you can see that happen with get_the_block_template_html(): https://github.com/WordPress/wordpress-develop/blob/b5392cc28c6f065227e9345cdb9ac266a0f9ee30/src/wp-includes/template-canvas.php

You might be able to fix it by hacking the sage index.php although this would probably have other side effects:

+ <?php $content = view(app('sage.view'), app('sage.data'))->render(); ?>
<!doctype html>
<html <?php language_attributes(); ?>>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?php wp_head(); ?>
  </head>

  <body <?php body_class(); ?>>
    <?php wp_body_open(); ?>
    <?php do_action('get_header'); ?>

    <div id="app">
-      <?php echo view(app('sage.view'), app('sage.data'))->render(); ?>
+     <?php echo $content; ?>
    </div>

    <?php do_action('get_footer'); ?>
    <?php wp_footer(); ?>
  </body>
</html>