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
- Enter
<p>Hello</p>
in HTML editor for new post - Click PUBLISH, published post is formatted correctly
- Contents of editor changed after the PUBLISH refresh to
Hello
(p tags gone) - 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:
- Customized Roots theme, no hackery.
- Plugins: Akismet, Advanced Custom Fields, Custom Post Type UI, Google Analytics for WP
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.: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
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.
If it is complicated for you to practically shut down a live site for doing this, two options: