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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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);
}
add_filter('the_content','clear_br');
Note that I’ve put "<br>" tag which is what wordpress creates when you enter newline characters.
Method 2
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:
- https://wpengine.co.uk/resources/wordpress-formatting-issues/
- https://webhostinghero.org/preserve-line-breaks-and-formatting-in-wordpress/
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0