WordPress – text area linebreaks as seperate P tags (without creating empty p-tags where linebreaks where)

I have a custom textarea are that I normally just output using ‘nl2br‘. In this particular case I need to wrap them in separate Paragraph tags, instead of have '
'
.

I’m currently using this:

$memberDescription = '<p>' . implode('</p><p>', array_filter(explode("n", get_post_meta( get_the_ID(), 'members_' . $z . '_description', true )))) . '</p>';

My issue is that when I echo this out, it also outputs empty Paragraph tags (im guessing where extra line breaks are).

Any tips or tricks on how to alter this to remove the empty P-tags, or have them not even outputted, to begin with, would be greatly appreciated.

Read more here: WordPress – text area linebreaks as seperate P tags (without creating empty p-tags where linebreaks where)

Leave a Reply

Your email address will not be published. Required fields are marked *