From f86463bc77e51b52cc1af790134ae5ccad2b6384 Mon Sep 17 00:00:00 2001 From: Dhananjay Kuber Date: Thu, 16 Jan 2025 11:44:52 +0530 Subject: [PATCH] fix: handle empty content in heading block rendering --- packages/block-library/src/heading/index.php | 2 +- packages/block-library/src/heading/save.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/heading/index.php b/packages/block-library/src/heading/index.php index 471e31f19f2ee9..c2d7e4911a9203 100644 --- a/packages/block-library/src/heading/index.php +++ b/packages/block-library/src/heading/index.php @@ -22,7 +22,7 @@ * @return string The content of the block being rendered. */ function block_core_heading_render( $attributes, $content ) { - if ( ! $content ) { + if ( ! $content || '' === trim( strip_tags( $content ) ) ) { return $content; } diff --git a/packages/block-library/src/heading/save.js b/packages/block-library/src/heading/save.js index 8ae4fa6afd9f6f..ac010511ab6e47 100644 --- a/packages/block-library/src/heading/save.js +++ b/packages/block-library/src/heading/save.js @@ -10,6 +10,11 @@ import { RichText, useBlockProps } from '@wordpress/block-editor'; export default function save( { attributes } ) { const { textAlign, content, level } = attributes; + + if ( ! content || content.trim() === '' ) { + return null; + } + const TagName = 'h' + level; const className = clsx( {