# Remove Empty Paragraphs From Content

> Cleans up the empty paragraphs and stray line breaks left behind by pasted text, old page builders and shortcodes, so spacing stays even.

- Type: PHP
- Runs: Frontend only
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: cleanup, paragraphs, formatting
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/remove-empty-paragraphs/

## Code

```php
add_filter( 'the_content', function ( $content ) {
    $result = preg_replace( '/<p(?:\s[^>]*)?>(?:\s|&nbsp;|&#160;|<br\s*\/?>)*<\/p>/i', '', $content );

    return null === $result ? $content : $result;
}, 20 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Remove Empty Paragraphs From Content" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
