Contents of HTML editor mangled after multiple UPDATES

In a perfect world, WordPress would take what I enter into the HTML editor and write it verbatim into the post/page document received by the browser. Disabling wpautop has already helped me slightly to this end. Alas..

Setup: I write some HTML into the editor and click UPDATE. My post/page is formatted correctly, but the contents of my editor have changed: p and br tags are gone, replaced respectively with actual empty lines and line breaks. When I view source, the contents of the editor textarea are what I originally typed, but its as if p and br tags are actually being rendered in the textarea.

The problem is that when I click UPDATE again (without changing anything), the post/page is formatted incorrectly, because said tags are lost.

How can I get my HTML editor contents not to be automatically mangled? I do not ever switch over to the visual editor. Just scanning through wp-includes/formatting.php, the function format_to_edit seems promising, but unsure how to proceed.

Example

  1. Enter <p>Hello</p> in HTML editor for new post
  2. Click PUBLISH, published post is formatted correctly
  3. Contents of editor changed after the PUBLISH refresh to Hello (p tags gone)
  4. Click UPDATE, post is formatted incorrectly due to lack of p tags

UDPATE

After looking at some of the comments/answers and doing some testing, this does look like a hackery side-effect. I can’t repro in a fresh install of Roots. Here are the details of my install:

  1. Customized Roots theme, no hackery.
  2. Plugins: Akismet, Advanced Custom Fields, Custom Post Type UI, Google Analytics for WP

2 Answers
2

It may help you to render content in your theme directly without the_content filter, although you would loose thigns like oembeds etc e.g.:

echo $post->post_content;

However this sounds like a symptom of a hack. If you have something complex like an embed then you should be using either oembed ( e.g. youtube, don’t be pasting the raw embed stuff ) or using a shortcode. Else there’s very, very few reasons to keep the html markup for things like p and br tags for ordinary content, and if you’re using div containers and other layout elements then you’re doing it wrong

Leave a Comment