{"id":1168,"date":"2010-10-23T16:14:12","date_gmt":"2010-10-23T15:14:12","guid":{"rendered":"http:\/\/www.simonbattersby.com\/blog\/?page_id=1168"},"modified":"2015-01-15T08:44:15","modified_gmt":"2015-01-15T08:44:15","slug":"plugin-to-stop-wordpress-adding-br-tags","status":"publish","type":"page","link":"https:\/\/www.simonbattersby.com\/blog\/plugin-to-stop-wordpress-adding-br-tags\/","title":{"rendered":"Plugin to stop WordPress adding &lt;br\/&gt; tags"},"content":{"rendered":"<p>Quite a while ago I wrote a <a href=\"\/blog\/2009\/08\/stop-wordpress-adding-br-tags\/\" title=\"View original post\">blog post<\/a> about stopping WordPress adding <code>&lt;br\/&gt;<\/code> into your posts, a particularly irritating habit. The solution I posted involved editing the function <code>wpautop()<\/code> in formatting.php, specifically changing this:<\/p>\r\n\r\n<pre>function wpautop($pee, $br = 1)<\/pre>\r\n\r\n<p>to this:<\/p>\r\n\r\n<pre>function wpautop($pee, $br = 0)<\/pre>\r\n\r\n<p>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&#8217;re interested, here&#8217;s the detail. <code>wpautop()<\/code> most noticeably adds <code>&lt;p&gt;<\/code> tags around (what it thinks are) paragraphs, as well as adding the <code>&lt;br\/&gt;<\/code> and a host of other formatting stuff. It&#8217;s easy enough to get rid of the function altogether via:<\/p>\r\n\r\n<pre>remove_filter('the_content','wpautop');<\/pre>\r\n\r\n<p>However, I didn&#8217;t want to disable the paragraph formatting, particularly on a site for a client, just sort the &lt;br\/&gt;. So here&#8217;s the whole plugin code: <strong>Amended 31 March 2014<\/strong><\/p>\r\n\r\n<pre>&lt;?php\r\n<span class=\"code_comment\">\/*\r\nPlugin Name: Better wpautop \r\nPlugin URI: http:\/\/www.simonbattersby.com\/blog\/plugin-to-stop-wordpress-adding-br-tags\/\r\nDescription: Amend the wpautop filter to stop wordpress doing its own thing\r\nVersion: 2.0\r\nAuthor: Simon Battersby\r\nAuthor URI: http:\/\/www.simonbattersby.com\r\n*\/<\/span>\r\n\r\nfunction better_wpautop($pee){\r\nreturn wpautop($pee,false);\r\n}\r\n\r\nremove_filter( 'the_content', 'wpautop' );\r\nadd_filter( 'the_content', 'better_wpautop' , 99);\r\nadd_filter( 'the_content', 'shortcode_unautop',100 );\r\n?&gt;<\/pre>\r\n\r\n<p>All I&#8217;m doing is defining a function <code>better_wpautop()<\/code> which calls the existing function, setting the <code>$br<\/code> variable to 0<\/p>\r\n\r\n<p>Feel free to use this. <strong>If you&#8217;re downloading this after 31 March 2014, it&#8217;d be great to know if it works for you so leave me a note below<\/strong>. To add as a plugin, download the <a href='\/demos\/plugins\/better-wpautop.zip'>zip file<\/a>, unzip in your plugins folder and activate via the admin panel<\/p>\r\n\r\n<div id=\"plugin\" class=\"shadow roundbox\"><h3>Better wpautop plugin<\/h3><p id=\"plugin_desc\">To install the plugin, download the zip file by clicking on the icon, unzip, load into your WordPress plugins folder and activate.<\/p><p id=\"plugin_media\"><a href='\/demos\/plugins\/better-wpautop.zip'><img decoding=\"async\" src=\"\/blog\/wp-includes\/images\/crystal\/archive.png\" alt=\"Better wpautop plugin\" title=\"Better wpautop plugin\"\/><\/a><\/p><\/div>","protected":false},"excerpt":{"rendered":"<p>Quite a while ago I wrote a blog post about stopping WordPress adding &lt;br\/&gt; 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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1168","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages\/1168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/comments?post=1168"}],"version-history":[{"count":2,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages\/1168\/revisions"}],"predecessor-version":[{"id":2953,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages\/1168\/revisions\/2953"}],"wp:attachment":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/media?parent=1168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}