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.

Read More

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

Related posts

Leave a Reply

2 comments

  1. 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

  2. I had this issue once and it was caused, as Ashfame comments and Tom J Novell mentions, by a double hackery stuff.

    My functions.php was removing some the_content filters and a plugin (don’t remember which) was doing the same.

    There are some basic troubleshooting steps that you may take. They are outlined in this post by the always cognoscenti Ipstenu. I’ll reproduce the steps bellow, but the article is worthwhile reading in full.

    • flushing any caching plugins you might be running, as well as server and/or browser caches.

    • deactivating all plugins (yes, all) to see if this resolves the problem. If this works, re-activate the plugins one by one until you
      find the problematic plugin(s). If you can’t get into your admin
      dashboard, try resetting the plugins folder by FTP or PhpMyAdmin.
      Sometimes, an apparently inactive plugin can still cause problems.
      Also remember to deactivate any plugins in the mu-plugins folder. The
      easiest way is to rename that folder to mu-plugins-old

    • switching to the Twenty Eleven theme to rule out any theme-specific problems. If you can’t log in to change themes, you can remove the
      theme folders via FTP so the only one is twentyeleven. That will force
      your site to use it.

    • manually upgrading. When all else fails, download a fresh copy of the latest.zip file of 3.3 (top right on this page) to your computer,
      and use that to copy up. You may need to delete the wp-admin and
      wp-includes folders on your server. Read the Manual Update directions
      first!

    If it is complicated for you to practically shut down a live site for doing this, two options: