Empty paragraph, heading, group, and column blocks in the Block Editor create unwanted spacing on your site, but these simple filters automatically remove them before they render.
The Block Editor brought flexible content creation to WordPress, but it also introduced a new problem: empty paragraph and heading blocks that create unwanted spacing. These invisible elements weren’t an issue with the classic editor.
Empty blocks sneak into content when editors work with Gutenberg or Full Site Editing themes. Content teams accidentally leave them behind during editing, and they’re nearly impossible to spot in the Block Editor interface. Unlike the classic editor, where you could see empty paragraphs directly in the HTML, the Block Editor hides these gaps.
These invisible elements mess up your design spacing and frustrate content teams. They show up as empty <p> or <h1-h6> tags in your HTML, creating gaps where none should exist. Empty group or column wrappers add to the problem. The Block Editor doesn’t always make it obvious when a block contains only whitespace or non-breaking spaces.
I filter out these empty blocks before they render on the frontend. Two simple functions check paragraph and heading blocks for actual content and prevent empty ones from appearing in your markup. This approach keeps your HTML clean without requiring content editors to hunt down invisible blocks.
Here’s the solution:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters