Skip to content

Instantly share code, notes, and snippets.

@greg-randall
Created February 26, 2024 20:35
Show Gist options
  • Save greg-randall/d0b9dacad86e8d0e20a94d472a32914a to your computer and use it in GitHub Desktop.
Save greg-randall/d0b9dacad86e8d0e20a94d472a32914a to your computer and use it in GitHub Desktop.
Works like "do_shortcode" but for Gutenberg blocks.
function do_gutenberg( $content ) {
$output_rendered = "";
$parsed_blocks = parse_blocks( $content );
if ( $parsed_blocks ) {
foreach ( $parsed_blocks as $block ) {
$output_rendered .= apply_filters( 'the_content', render_block( $block ) );
}
}
return ( $output_rendered );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment