Created
July 23, 2024 21:38
-
-
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.
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
<?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