It’s not working because:
-
Maybe your filter is running to early as Benoti said in his comments, your filter callback may run before the empty paragraphs are added.
-
Maybe you are dealing with something different than am empty
<p></p>
, think<br>
,
…
Solution 1:
Disable autop
(remove it’s filter).
Solution 2:
add_filter('the_content', 'wpse_244389');
function wpse_244389($content) {
$pattern = '#<p>(\s| |</?\s?br\s?/?>)*</?p>#';
$content = preg_replace( $pattern, '', $content );
return $content;
}