Skip to content

Commit

Permalink
fix: handle empty content in heading block rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
dhananjaykuber committed Jan 16, 2025
1 parent 9f7d7dc commit f86463b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/block-library/src/heading/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/heading/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down

0 comments on commit f86463b

Please sign in to comment.