Skip to content

Instantly share code, notes, and snippets.

@coulterpeterson
Created May 15, 2024 20:01
Show Gist options
  • Save coulterpeterson/1bf619b76483f5792aa9d8c05712c193 to your computer and use it in GitHub Desktop.
Save coulterpeterson/1bf619b76483f5792aa9d8c05712c193 to your computer and use it in GitHub Desktop.
How to use a WordPress Block in a custom page template
// Source block markup can be retrieved from the posts table in the database after you configure a block on a page
$your_block = '<!-- wp:heading {"level":1} -->
<h1>Heading 1</h1>
<!-- /wp:heading -->';
$parsed_blocks = parse_blocks( your_block );
if ( $parsed_blocks ) {
foreach ( $parsed_blocks as $block ) {
echo render_block( $block );
//echo apply_filters( 'the_content', render_block( $block ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment