I have a problem with WP that need your help. Some of my posts have content that was applied “wp_autop” filters already. This filter turned all double break lines into <p>
tag. I want to the opposite thing: turn all <p>
tag into double break lines.
Do you have any suggestions? Thank you.
I just ran into this situation. Here is a function I used to undo wpautop. I might be missing something, but this is a good start:
function reverse_wpautop($s)
{
//remove any new lines already in there
$s = str_replace("\n", "", $s);
//remove all <p>
$s = str_replace("<p>", "", $s);
//replace <br /> with \n
$s = str_replace(array("<br />", "<br>", "<br/>"), "\n", $s);
//replace </p> with \n\n
$s = str_replace("</p>", "\n\n", $s);
return $s;
}