From 1ee3574d03f75ed3016267f2fdfbc78f468fcaa0 Mon Sep 17 00:00:00 2001 From: Dome Date: Sat, 2 May 2026 17:37:19 +0200 Subject: [PATCH] load code-block code only if needed --- inc/tools/code-block.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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, '