<?php
$post = get_post( 123 ); // Replace 123 with your post ID
if ( ! $post ) {
return;
}
$blocks = parse_blocks( $post->post_content );
// $blocks is an array of block arrays and text nodes
foreach ( $blocks as $block ) {
if ( isset( $block['blockName'] ) && $block['blockName'] === 'my-plugin/my-block' ) {
// Found the block instance
$html = render_block( $block );
echo '<div class="outside-container">';
echo $html;
echo '</div>';
// If you only want the first, break here.
}
}
WP开发教程 WordPress导师在线教程