I've spent about 3 hours trying out various functions to figure out why the newline characters are being removed every time I save.

How do I figure out why is wordpress suddenly stripping away newline characters? I have not installed any plugins. How can I get newline characters to show up on my site without converting all blocks to HTML and modifying everything in code?

  • Do you have an example of what you mean? The snippet you added as an answer implies that WordPress is still adding <br> tags, so what's being removed? Commented Aug 4, 2020 at 1:07
  • @JacobPeattie The snippet I added gets triggered when you hit "save". The br tags will exist until you hit save. While saving WP brilliantly removes all consecutive br tags but lets them be present in the UI. This snippet adds an attribute which prevents wordpress from automatically removing them..
    – Mugen
    Commented Aug 5, 2020 at 5:00
  • This is how the editor is supposed to behave. The newlines are automatically converted back into <br> tags on output. Commented Aug 5, 2020 at 5:14
  • @JacobPeattie But that is not happening. I haven't checked in the DB how it's storing internally and whether it's converting it back automatically or not. But from a blackbox perspective I see that 3 br tags gets converted to a single br tag. this issue in wordpress and it's fixed with the snippet that I pasted in the answer.
    – Mugen
    Commented Aug 5, 2020 at 9:19

2 Answers 2


I found the following snippet which we can add to functions.php . I'm adding these via a plugin.

function clear_br($content) { 
return str_replace("<br>","<br clear='none'>", $content);

Note that I've put "<br>" tag which is what wordpress creates when you enter newline characters.


I have the same issue. For me with Beaver Builder I have to choose a Classic Block and then pasting with newlines works.

Two useful links:

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.