diff --git a/inc/tools/code-block.php b/inc/tools/code-block.php index dd227ed..ea7cbb4 100644 --- a/inc/tools/code-block.php +++ b/inc/tools/code-block.php @@ -16,6 +16,34 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } +/** + * Check if current post content contains code blocks. + * + * @return bool + */ +function ztfr_has_code_block() { + + if ( is_admin() ) { + return false; + } + + if ( ! is_singular() ) { + return false; + } + + global $post; + + if ( ! isset( $post ) || empty( $post->post_content ) ) { + return false; + } + + if ( has_block( 'ztfr/code-block', $post ) ) { + return true; + } + + return false !== strpos( $post->post_content, '