Stop WordPress adding <br/> tags

Been swearing at WordPress this afternoon…

I’ve been trying to transfer an html form, which I had working perfectly on a static html page, onto a WordPress page. WordPress insisted on adding multiple <br/> tags where I didn’t want them. Mutter.

Eventually, after much searching, I identified a parameter within wp-includes/formatting.php, which allows you to disable this irritating feature. If you open formatting.php and find the function wpautop you’ll see this:

function wpautop($pee, $br = 1)

Change this to:

function wpautop($pee, $br = 0)

Save the file and publish it back to your server and that’s it. Works fine in WP2.8.

Note: WP 2.8.3 overwrites formatting.php so this change needs redoing.

Update 24 October 2010

Fed up with repeatedly doing this I’ve developed a WordPress plugin to address the issue. Give it a try and let me know if it works for you.

Tags: ,

16 responses to “Stop WordPress adding <br/> tags”

  1. Lima says:

    cheers, mate!

  2. Great solution! It works perfectly! Thanks for sharing!

  3. I can now stop headbutting the desk – until the next update.

  4. Don says:

    Awesome. I too was doing some headbutting. $#%!!!

    Thanks a lot for posting this solution!

  5. Jason says:

    Thank you so much!

  6. Justin says:

    Awesome – this helped me out heaps. Thank you.

  7. Sierra says:

    You are a life-saver! I am forever indebted to you!

  8. Kris says:

    Great post – thanks so much.
    What an annoying little feature that is – auto adding line breaks behind your back!

  9. iamebet says:

    Thanks!!! I was stumped with this one when creating some shortcodes.

  10. Joyce says:

    Thanks a million, I was pulling my hair out!

  11. Ben says:

    Thanks! This was driving me crazy!!! And this fixed it :-)

  12. wjzhb says:

    tx!It can solve the problem

  13. Graham says:

    You total and utter legend – its been driving me nuts

  14. Justin says:

    Definitely NOT the proper way to do this guys. If you ever update WordPress, you’ll need to edit this each time. Best option is to wrap the fix in a custom function.

  15. Simon says:

    …which is what I’ve said, and why I wrote the plugin…

  16. Tommy says:

    THANKS!!!!

Useful? Interesting? Leave me a comment