9

I am tired of WordPress's horrible HTML editor and have decided to write all my html in Notepad++ and then just copy it over. However, simple line breaks "\n" that would be normally ignored in html are converted to <br /> tags. I have disabled the visual editor, so everything I save should be the exact html that is presented. But it's not. how do I stop wordpress from converting my html?

1
  • Well, the <br /> tag is exactly a line break in HTML. If you use line breaks in Notepad++ to create new paragraph just make two line breaks, WordPress will end the previous and begin a new paragraph. If you don't want line breaks in your post then why did you make them when writing the post in Notepad++? Nov 19, 2012 at 1:06

2 Answers 2

13

That's handled by a filter called wpautop (declared in wp-includes/formatting.php, line 189).

You can remove it with this:

remove_filter('the_content', 'wpautop');
4
  • You can also do this using plugin wpautop control and set site-wise default as well as per post setting. More info at blog.bigsmoke.us/2010/12/09/wpautop. Apr 11, 2014 at 1:05
  • Above solution from @jlenstorf does not appear to apply to my most-recent WordPress 4.x installs. This mature plugin seems popular. wordpress.stackexchange.com/a/227428/93125 May 22, 2016 at 0:02
  • @JohnnyUtahh I'm not sure if there's something else going on in your 4.x installs, but I just checked on a site running 4.5.2 and disabling the filter still works. If you look at the source of the plugin you linked, it's essentially doing exactly the same thing, but with a bunch of overhead on the admin side.
    – jlengstorf
    May 23, 2016 at 13:24
  • 1
    Great solution! And it still works on Wordpress: 4.7.5 I added remove_filter('the_content', 'wpautop'); to "/wp-content/themes/my_theme/functions.php" to keep everything in the same place.
    – Tarik
    Jun 18, 2017 at 8:56
1

Toggle wpautop plugin.

It's the most-popular solution I found, and works well for me. Above plugin page shows 10,000+ installs and 100% 5-star ratings (23 of them) as of 2016-05-21.

The description of the above plugin page:

Before WordPress displays a post's content, the content gets passed
through multiple filters to ensure that it safely appears how you
enter it within the editor.

One of these filters is wpautop, which replaces double line breaks
with <p> tags, and single line breaks with <br /> tags. However, this
filter sometimes causes issues when you are inputting a lot of HTML
markup in the post editor.

This plugin displays a checkbox in the publish meta box of the post
edit screen that disables the wpautop filter for that post.

Also adds a 'wpautop', or 'no-wpautop' class to the post_class filter
to help with CSS styling.

jlengstorf's answer does not appear to apply to my WordPress 4.x installs.

2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Sumit
    May 22, 2016 at 6:23
  • Got it, thanks. Does my recent update to the answer solve this? May 22, 2016 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.