Enabling Line Break “<br>” in WordPress

Finally!! A permanent solution in order to prevent WordPress from filtering line breaks "<br>" from a post.

In spite of trying various methods such as putting line breaks "<br>" inside "<code>" tag and many other such HTML tricks (many of which can be easily found at WordPress) just to be able to put multiple intentional line breaks in a post, wordpress would eventually manage to filter those line breaks. Even if the tricks were successfully applied, when it came to re-editing a post, all efforts would go to vain when TinyMCE initiates its own filtering process.

WordPress has a built-in powerful post/text editor commonly known as the “Visual” editor, which uses the open source project named “TinyMCE“. When switching from Visual to HTML editor in WordPress or vice-versa TinyMCE executes a back-end filtration process which removes empty tags, and <br> tags from the post.

Needless to say, it is very irritating when a author is forced to loose his/her creative ideas by forcing these kind of annoying and unnecessary filtration. Many has expressed their annoyance regarding this issue, as evident HERE.

Most of the time I would just reverse engineer stuff that really bugs me, silently and without complaining. But this time around I have found a solution for this problem without any reverse engineering.

TinyMCE-Advanced from wordpress is a wordpress plugin, which adds the option to disable the removal of <p> and <br> tags when saving a post and in the HTML editor (autop). After installing-activating, the option to enable line breaks can be found in the Settings->TinyMCE Advanced panel.

The plugin along with adding the functionality mentioned above provides the ability to add many more very useful buttons in the Visual editor, which is a big plus.

Blogging should be a little more easier from here on with the freedom of unlimited line breaks in wordpress :)…

Please feel free to suggest other ideas below and/or let me know if this did the trick for you too.

91 Responses to “Enabling Line Break “<br>” in WordPress”

Let me join those singing your praises. I spent three hours on this last night, utterly befuddled. Your write up is a model for technical writing: you explain the problem and present the solution so clearly that even a novice like me can resolve the problem. Many, many thanks!

I spent more than two hours trying to find a solution to the problem of disappearing HTML tags when switching back-and-forth between HTML and rich visual editor in WordPress. You explained the problem clearly and gave an elegant and useful solution. You rock. Thank you so much. TinyMCE Advanced is a wonderful plug-in.

Thank you! After a gruelling two days of setting up WordPress as my website CMS I had all but given up on unclunky formatting… Your post sent me in the right direction and taught me (a WordPress newbie if there ever was one) how to tweak the plugin exactly. That explanation is a life-saver! Cheers again!

I take that back, it did work. Please don’t think of this as comment spamming, I just didn’t fully understand how it worked. I typically work in the HTML instead of the visual editor. This plugin DOES work in WP 3.0.

Here we are, a year later, and this is both still the best answer, and sooooo much less than perfect! This editors plugin must constantly fight with the underlying structure of WP, and so it still refuses to allow you to have exactly what you lay out in your editor.

[...] Finally!! A permanent solution for WordPress formatting issues Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.Powered by WP Greet Box WordPress PluginThe exerpt below was taken from this original webpage: rubayathasan.com [...]

Thanks for this post. It has somewhat fixed the problem but not 100%. I don’t understand why the hell WordPress decides to strip out BR tags.

When enabling the option you mentioned, all it does is create a new CSS class called br_fixer and whenver I type out a proper BR tag, it gets replaced with a P tag using the br_fixer class so instead of getting a clean line break, I get two line breaks.

Sorry. the comment before removed some html tag. I rewrite the comment.

I am using wordpress 2.7.1 and TinyMCE Advanced 3.2. I also enabled the option “stop removing br and p”

It allows me to add break line in the Visual View. However, it also add an extra break line at the beginning and the end of the content whenever I save or update the content from visual view. Is there anyway to fix it?

For some reason, this partially fixed my issue, but the editor is still taking out half of the tags and replacing them with . Does anyone know the underlying PHP file that controls the WP logic on this? I want to strip out the find/replace PHP function since nothing else seems to work. I found several other suggestions… one said to use but when I do that, WP then adds an extra … it’s totally crazy. Thanks for the above suggestion, I never noticed that checkbox in TinyMCE.

yeah parker I’m still having the problem too. Rubayat I am sure that you do indeed rock, but apparently I need more rocking to rock my problem away. It’s still stripping out my br tag on one of the “pages” (this one: http://syzygysailing.com/crew) For the life of me I can’t get the text to always start below the image

Leave a Reply

This entry was posted on Sunday, March 1st, 2009 at 4:20 amand is filed under Plugin, Reviews. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.