Since WordPress 5.0 came out, the Gutenberg block is the new way to organize content in your blog posts or pages. I find this useful to make a custom layout in each post/page as it is easy to insert different blocks within a post. Now for some reason, I need to display a particular block in a fixed section within a template file. Here’s how I did it.

Render A Block In A Template

The first step is to create a regular block that you want to display or use an existing block.

Then convert that regular block into a reusable block. Give it a unique name. Wordpress saves these reusable blocks as wp_block post type.

The next step is getting the block ID (or technically, the post ID). We can get this by getting a post object using the block’s unique name. Example:

$partners = get_page_by_title('Our Partners', OBJECT, 'wp_block');

Once we got the post object, we can then reference it to render as a content.

echo apply_filters('the_content', '<!-- wp:block {"ref":'.$partners->ID.'} /-->');

Watch The Video