我在写作时使用的解决方案是检查Gutenberg HTML注释的post\\u内容。由于古腾堡未来的变化,这在未来可能行不通。
<?php
$post_content = get_the_content( get_the_ID() ); // Get the post_content
preg_match_all(\'<!-- /wp:(.*?) -->\', $post_content, $blocks); // Get all matches in between <!-- /wp: --> strings
// $blocks[1] contains the names of all the blocks present in the post_content
if ( in_array( \'heading\', $blocks[1] ) ) {
// Post content contains a wp:heading block
}
else {
// Post content does not contain a wp:heading block
}