How to remove specificly the last <p></p> tag in all posts in wordpress?

Viewed 39

I want to remove the last paragraph of content in all of my posts, which always have a

tag on their own.

example: <p>content I want to keep</p> 
         <p>content I want to remove<p/>
1 Answers

You can work with Regex:

preg_grep('/<p\b[^>]*>(.*?)<\/p>/', explode('\n', $input_lines));

that will return an array with every line of <p>...</p>. Unset the last key of that array and then keep working with it.

Related