Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
There's also a few plugins (like Disable WPautop) that will take care of this for you. –  Andrew Jan 20 '12 at 17:56
add comment

3 Answers

up vote 5 down vote accepted

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;      
}
share|improve this answer
add comment

The filter write not in the database, filter on frontend, when view the post or other content. You deactivate the filter and write a own filter for set your custom markup.

share|improve this answer
    
It might be he somehow added autop'ed content into the DB, that's what I understood from it. –  Xeross Dec 20 '10 at 14:28
    
Xeross is right. The autop'ed content was added into DB already. And I want to clean up it to un-autop version. –  Rilwis Dec 21 '10 at 3:38
1  
Maybe you can filter with sql all <p></p> and <br /> in the datebase. A esay way to do this is the plugin Search & Replace. –  bueltge Dec 21 '10 at 23:51
    
bueltge was referring to the Search and Replace (Wordpress Plugin). You can use it to easily search and replace in your database. –  hakre Feb 5 '11 at 23:39
add comment

There's a built in function in WordPress, but it's JavaScript only triggered when you switch from Visual to HTML in the post editor (and it's really buggy if html is actually used though). If its just normal post content (not html code) then you can just edit each post, switch the editor back and forth, then save.

This is probably the most labor intensive, but safest, way.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.