Created
May 15, 2024 20:01
-
-
Save coulterpeterson/1bf619b76483f5792aa9d8c05712c193 to your computer and use it in GitHub Desktop.
How to use a WordPress Block in a custom page template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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