load code-block code only if needed
This commit is contained in:
@@ -16,6 +16,34 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
exit;
|
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, '<pre' );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get asset version from file modification time.
|
* Get asset version from file modification time.
|
||||||
*
|
*
|
||||||
@@ -41,6 +69,11 @@ function ztfr_enqueue_code_assets() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🔥 Nur laden wenn Codeblock vorhanden
|
||||||
|
if ( ! ztfr_has_code_block() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$code_css_version = ztfr_code_asset_version( '/assets/css/code.css' );
|
$code_css_version = ztfr_code_asset_version( '/assets/css/code.css' );
|
||||||
$prism_version = ztfr_code_asset_version( '/assets/js/prism.js' );
|
$prism_version = ztfr_code_asset_version( '/assets/js/prism.js' );
|
||||||
$code_js_version = ztfr_code_asset_version( '/assets/js/code-block.js' );
|
$code_js_version = ztfr_code_asset_version( '/assets/js/code-block.js' );
|
||||||
|
|||||||
Reference in New Issue
Block a user