Need some help?

I'm usually available for small jobs or problem solving with jQuery or css, at reasonable rates. Just get in touch.

Web Hosting

We recommend Clook for web hosting. UK based, great service and great value.

Buy me a drink

If you've found this useful, particularly for commercial projects, you might consider making a small donation.

Plugin to stop WordPress adding <br/> tags

Quite a while ago I wrote a blog post about stopping WordPress adding <br/> into your posts, a particularly irritating habit. The solution I posted involved editing the function wpautop() in formatting.php, specifically changing this:

function wpautop($pee, $br = 1)

to this:

function wpautop($pee, $br = 0)

Now, this works fine, but whenever you upload a new version of WordPress, the change gets overridden and you have to do it again. If you’re interested, here’s the detail. wpautop() most noticeably adds <p> tags around (what it thinks are) paragraphs, as well as adding the <br/> and a host of other formatting stuff. It’s easy enough to get rid of the function altogether via:

remove_filter('the_content','wpautop');

However, I didn’t want to disable the paragraph formatting, particularly on a site for a client, just sort the <br/>. So here’s the whole plugin code: Amended 31 March 2014

<?php
/*
Plugin Name: Better wpautop 
Plugin URI: http://www.simonbattersby.com/blog/plugin-to-stop-wordpress-adding-br-tags/
Description: Amend the wpautop filter to stop wordpress doing its own thing
Version: 2.0
Author: Simon Battersby
Author URI: http://www.simonbattersby.com
*/

function better_wpautop($pee){
return wpautop($pee,false);
}

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'better_wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );
?>

All I’m doing is defining a function better_wpautop() which calls the existing function, setting the $br variable to 0

Feel free to use this. If you’re downloading this after 31 March 2014, it’d be great to know if it works for you so leave me a note below. To add as a plugin, download the zip file, unzip in your plugins folder and activate via the admin panel

Better wpautop plugin

To install the plugin, download the zip file by clicking on the icon, unzip, load into your WordPress plugins folder and activate.

Better wpautop plugin

67 responses to “Plugin to stop WordPress adding <br/> tags”

  1. diego says:

    working great on 2022! awesome job!

  2. Jen says:

    Had 5,000+ html files to import and WordPress was putting br right the way through, driving me crackers. This plugin still works a treat, total lifesaver.

  3. Jean-Simon says:

    Still Working great with 5.1.1, Thank you Simon

  4. Simon says:

    Line 429 of formatting.php is:

    function wpautop( $pee, $br = true ) {

    That’s what you want.

  5. ibrahim says:

    Hi Simon,
    I can’t find this code in formatting.php. I saw this code : function wpautop($pee, $br true
    What can i do? Please help me

  6. Simon says:

    Mike
    I’m not sure why it doesn’t work for you. It’s possible that your theme or another plugin is interfering – although that would be unusual. If you’re able, change to a vanilla theme and/or disable your other plugins.

  7. Mike says:

    Hi,
    It doesn’t work for me.. WP still keeps adding the ..

  8. Dhirendrasinh Rathod says:

    Mind Blowing solution Thank you…!!!

  9. Simon says:

    Depends how you are parsing the text entered on the form before storing it in your database. You might want to look at the PHP function nl2br or google the often used local function nl2p.

  10. Sewa Rumah says:

    I create a form to insert post into wp.
    if the user input several lines, why it becomes one line in wordpress?

    line 1
    line 2

    becomes

    line 1 line 2

  11. Works like a dream! Thanks man!

  12. Krisztina says:

    Thank you for this plugin.

    I’m a WP beginner, but have had some basic experience with other CMS and HTML / CSS. For half a day, I had been inspecting my css which worked on a custom html page perfectly but became a scary mess when inserted into a WP “page”, apparently because of the line break tags. Thank you very much for the solution. Worked with 4.2.3, did the upgrade to 4.2.4, still working! 🙂

  13. Simon says:

    Didn’t realise it wasn’t on this page! It is now….

  14. Kim says:

    BLESS YOU!

    Do you have a donate button lying around? I’d love to buy you a beer.

    Running on WordPress 4.1

    Thanks so much!!

  15. Tia says:

    Oh my goodness. Thank you so much. I have never run into this problem until today and your plugin fixed the issue right away. I am using WordPress 4.1 and it is working beautifully. 🙂

  16. jef says:

    Thank you so much! How maddening this problem was. My H tags had an annoying break before them using a column shortcode. This has solved it for me without destroying hard returns. Thank you so much! (BTW working fine in 4.0.1

  17. Dan Burhans says:

    Thanks for this. Plugin working fine in WordPress version 4.0.1

  18. Simon says:

    The first thing would be to check the html generated by the widget, and see if that’s causing the issue. The plugin solves the problem created by WordPress built in filter which runs on post content, so a widget will not be affected by this anyway.

  19. Todd says:

    Hi Simon! Thanks for getting back here. Is there any solution for widgets in the sidebar that have forms in them? You rock. Thanks!

  20. Simon says:

    There’s no way of knowing what’s happening from a screenshot, but my plugin will work only on post content. If your payment plugin is running the form as a widget (for example) then the
    tags are possibly being added directly, in which case you’d need to look at the html that your plugin generates.

  21. Todd says:

    Hi Simon,

    I’m using your plugin (to no avail yet). The issue I’m having is I’m using the WordPress PayPal Payment Plugin on a Genesis theme using a sidebar widget. It’s still adding an extra tag as you can see here: http://prntscr.com/55jzqy

    Maybe I’m doing something wrong?

  22. John says:

    Works fine here – thanks for taking the time to do this. ( October 2014 WP4)

  23. Emma says:

    Magic! Worked for me with tables (October 2014 WP 4.0)

  24. WP Plugin says:

    Simon, the plugin is exceptional for WP beginners like me, thank you very much for sharing!

  25. Sara says:

    Why does this happen?

    I stumbled on your plugin searching for what was causing 20 tags to be inserted in a Paypal form sitting in a table cell. I installed it as a last resort before beginning days of forum posting…

    Can’t thank you enough.

  26. Simon says:

    Heh, you’re right, I get the same result. This is a combination of the formatting applied through the WordPress wpautop function and the html it generates for a gallery, and isn’t fixable with this plugin. The issue I think is that the standard wp gallery doesn’t allow you to set ‘none’ for the number of columns in a gallery to enable a responsive design. This can be addressed, sort of, by .gallery br {display: none;} in your css.

  27. Pablo says:

    The plugin works great!!! Thanks a lot, it save me hours

  28. Dennis says:

    I tried using this with WP 3.9.1 to remove break tags from galleries and after installing WordPress added paragraph tags around the break tags instead of removing anything. Thanks for your hard work on this frustrating issue: hope my post helps in development.

  29. Jason Carlin says:

    Installed on May 13, 2014. Worked right away. Thanks very much.

  30. Simon says:

    Thank you, these are valid points, and I have amended the plugin which I believe addresses your issue. Shame you had to make the points in such a manner, and anonymously…

  31. nk says:

    Well, the problem is, this solution changes the order of the assigned filters. wpautop now runs after shortcode_unautop and other replacements, which is quite senseless.

    So the better way, the hacky way, could be to assign your callback directly to the filter variable like this:

    $wp_filter[‘the_content’][10][‘wpautop’][‘function’] = ‘better_wpautop’;

    Additionally, the way you call the funktion is wrong. There’s no reason to use $br here – The call only uses the value you send. In short: use false or 0.

  32. Josiah says:

    I’m a web designer and this is a wonderfully helpful plugin. Thank you so much:)

  33. Simon says:

    Hi Wayne
    The plugin works fine for me on 3.8.1 without the change. PHP will interpret 1 as true and 0 as false anyway.

  34. Wayne Jackson says:

    In the latest version of wordpress 3.8.1 it does not use 0 or 1 anymore. You need to edit function wpautop($pee, $br = true) and change it to:

    wpautop($pee, $br = false)

  35. Simon says:

    As far as I can remember there was a bug some while back which prevented uploading images – maybe that’s what you’re seeing. Can you not upload images via Media and then link to them instead?

  36. Aaron Christe says:

    Thank you! Ended an hour or so of frustration

  37. Dave says:

    It took me so long to figure out that it was wpautop messing up my formatting. Thank you, very useful.

  38. Simon says:

    The code given is the whole code for a plugin. If you’re pasting into functions.php then you need to remove the starting and ending php tags and paste the code below before the existing closing php tag in your functions php (?>):

    function better_wpautop($pee){
    return wpautop($pee,$br=0);
    }
    
    remove_filter('the_content','wpautop');
    add_filter('the_content','better_wpautop');
  39. Bonnie says:

    Let me try this again without the code snippet… when i take your code exactly as it is and paste it at the end of the functions.php file. I get an error saying “an unexpected < in the code on line 258". I am not a php expert, so i believe i am just missing a little something… any help?

  40. Lifesaver! Thanks for making the plugin.

  41. Simon says:

    Tim

    It’s possible the tags are coming from MailChimp itself rather than WordPress. Another last ditch approach if you can’t edit the MailChimp html is to set the <br/> tags to display:none via your css. This won’t work of course if the MailChimp form is in an iframe.

  42. Tim says:

    Not working for me.
    I am having the same issues as you. Adding a form (MailChimp) inside a page

  43. Tony B says:

    Awesome – I just wished I’d noticed those extra tags in the page source code (of a form) instead of chasing non-existing conflicting stylesheets for three hours! Thanks so much.

  44. Ramil says:

    Thanks for this function. Save me a lot of headache! 😉

  45. Emily says:

    YAY! Thank you! Works great!

  46. RED says:

    Brilliant! Thank you so much for this quick fix.

  47. Adrian says:

    Thanks – also put this in functions.php and works great

  48. Lance says:

    I would send you 20 virgins if I could. This plugin saved me from blowing my brains out. Thank you!

  49. Alex says:

    Finally!!! Thanks!

  50. IS says:

    Thanks, you just ended 20 minutes of aggravation.

  51. John Clarke says:

    I added this (including your credits) into my functions.php file and it works perfectly.

    Thank you very much for publishing a simple solution to a problem that has been bugging a lot of people for a very long time.

  52. Ricky says:

    This works great! 3.3.1. WP added 10 br tags to every page I created.

  53. Simon says:

    It works fine for me in 3.3.1 – previous commenter Sophie also got it working OK.

  54. Awais says:

    I am using WordPress version 3.3.1 and i tried this hack and it did not work for me. Is it just me or someone also getting this problem? ðŸ™

  55. Simon says:

    Hi Bron

    It works OK with the visual editor disabled. I use this approach myself, but just have visual editor disabled against my user, rather than via a plugin.
    You could try adding the code to your theme’s functions.php and see if that works for you. Possibly something in your visual editor disabling plugin is interfering.

  56. bron says:

    I have diable visual editor plugin enabled and visual editor turned OFF AND using this plugin and still it adds BR to my posts why?

    It is because this only work WITH the visual editor ON

  57. Simon says:

    Yes, just tested it and it works fine.

  58. Sophie says:

    Is this still working with WP 3.3.1? I included it in my theme’s function.php and so far I don’t see any difference…

  59. JMac says:

    Thanks a lot for this! Just learning about WordPress and this was really pissing me off as well!!

  60. Ahmad Humeid says:

    It worked! I think this solves a big issue for me. Thank you!

  61. Brian FitzGerald says:

    Worked wonders for me, thanks for posting this solution!

    – WordPress 3.2.1

  62. David says:

    AWESOME!! Fixed it for me too, I added the code to functions.php and it works perfectly! Thank you 🙂 – WP3.2.1

  63. Simon says:

    The WP visual editor does fight back, yes. I have mine disabled completely, but if this isn’t an option, I’m not clued up on any fixes I’m afraid.

  64. Paul says:

    Now that I have installed Better Wpautop, I realized that the visual editor is stripping our paragraphs and line breaks. Is there a suggested change to fix the visual editor?

  65. Charles says:

    Thanks! This was driving me crazy! I’m running WP 3.1.4

  66. Chris says:

    thanks. solved in two minutes a problem I might have taken hours to find and fix (also – thanks JG @1 – I also just dumped the code in functions.php)

  67. Thanks for this. I put the code in my functions.php file and it work perfectly. I appreciate it.

Useful? Interesting? Leave me a comment

I've yet to find a way of allowing code snippets to be pasted into Wordpress comments - so if you're trying to do this you'd be better off using the contact form.