Skip to content

Instantly share code, notes, and snippets.

@brandonkramer
Created July 23, 2024 21:38
Show Gist options
  • Save brandonkramer/6291c8e4278c23416d323b808e412056 to your computer and use it in GitHub Desktop.
Save brandonkramer/6291c8e4278c23416d323b808e412056 to your computer and use it in GitHub Desktop.
In a WordPress block-based theme, use has_block() to check if the home template, homepage, or front-page includes a certain block.
<?php
if ( wp_is_block_theme() && is_front_page() ) {
$block_template = get_block_templates( [ 'slug__in' => [ 'home' ] ] );
$block_content = isset( $block_template[0] ) ? $block_template[0]->content : '';
$home_has_block = has_block( 'my/block', $block_content );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment