How can I disable automatic paragraph tags, but retain line breaks?

I have used this to remove wpautop:

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

But there are no more line breaks in the text.

  • 2
    Could you elaborate on what exactly you mean? You want <br /> tags, I assume? (EOLs should be there) May 8, 2013 at 22:14
  • Yes, I want br tags. Do you mean a simple nl2br function should do it?
    – Pier
    May 8, 2013 at 23:03
  • Yes, a simple nl2br function did it!
    – Pier
    May 8, 2013 at 23:14
  • @Pier Add a real answer with your working code please. Accept that answer and get some rep. :)
    – fuxia
    May 9, 2013 at 4:43

1 Answer 1


Here's the full solution.

First disable wpautop in your functions.php

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

Then parse your content/excerpt with nl2br (a standard PHP function).

add_filter( 'the_content', 'nl2br' );
add_filter( 'the_excerpt', 'nl2br' );
  • That will work, but it's very rudimentary, so you'll need to be look out for unintended side effects. For example, shortcodes will probably no longer work. Apr 30, 2014 at 23:14
  • 1
    I wouldn't make this a filter, for that reason, but I would put it in single-post.php as echo nl2br(do_shortcode($post->post_content), true); Otherwise, allowing wpautop creates a whole host of other problems with your html in posts.
    – kloddant
    Nov 8, 2018 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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