Replace empty paragraph – WordPress

Replace empty paragraph tags with newline in WP.

add_filter( ‘the_content’, ‘askiw_replace_empty_p’ ); Takes all blank paragraphs <p></p> in the body of each article and replaces it with an html newline tag <br>

/**
How to replace empty paragraph tags with newline in WP.
*/
function askiw_replace_empty_p( $content ) {
    $replace = array( 
        '<p></p>' => '<br>'
    ); 
    return strtr( $content, $replace );
}
add_filter( 'the_content', 'askiw_replace_empty_p' );

Leave a Reply