Support » Fixing WordPress » wp screwed the html code

  • i created a page using the code option instead of the visual editor.
    the html code of the page looks like this:

    <div id="left"><p>lorem ipsum</p></div>
    <div id="right"><p>lorem ipsum</p></div>

    a few days later, i wanted to edit that page, so i went through “manage pages” and found out that wordpress changed the code of my page, which now looks like that:

    <p id="left">lorem ipsum
    <p id="right">lorem ipsum

    how can i prevent wordpress to change the html code of my pages, if i want to edit them using the code editor?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Well, I’ve been looking in the forum for a few hours now and have tried every ‘hack’ that was mentioned, but unfortunately none of them worked for me..
    It looks like, in your case, you could edit the code directly in the database (in my case, the p tags aren’t shown in the database…) and you could edit it there.

    If I’m not mistaken, this bug has been around since v2.0 or v2.1. I’ve commented every line in the wpautop function (formatting.php), except the first line. Also edited a file in the tiny_mce directory (got that idea from somewhere around here), but unfortunately nothing works for me..

    Oh right, I even downloaded a plugin to disable the wpautop function (didn’t work and after that I tried commenting lines inside the function). I’ve already got the visual editor disabled since the beginning and I don’t allow WordPress to auto-correct xhtml.
    I haven’t got a clue on where to search next, but I do know I’m getting soar eyes and a headache of staring at my screen for so long..

    Hope you’ll find the answer though, if you do, please post it here 🙂

    haven’t found nothing useful so far 🙁

    do you think that this is a bug?

    and do you think that wp < 2.0 didn’t screw up the code in that way? i might try to look for an older version…

    Yes, it is messing with me, too. Totally not allowing me to put the submit button on form. 😛 Sometimes, just when I’m really liking WP, stuff like this crops up. I’ll have a solution by day’s end that I’ll share.

    Did anyone try this db-manager plug-in? It might let you blast whatever you want into the db via the WP interface, but I’ll consider this a last resort.

    I’ve gotten pretty good at figuring out what WP is doing and finding good ways of altering reality — usually via not using their easier tools and instead implementing my own hack in the template php file using their lower-level functions that drive their “user interface” wp_ type tools talked about in the codex.

    🙂 Chris

    Ah yes, the google-foo provides quick answer in wp support

    From: HandySolo

    Users -> Your Profile.
    Top checkbox – check it. Done.

    Tested and it will preserve html you put in there.

    found something here but still doesn’t work 🙁

    Yeah, turns out the “code” / “html” tool was screwing with html tags as well.

    Try this:

    worked for me…

    The function wpautop() has a lot of preg_replace commands with much much HTML tag swapping. Ew. I did the above simple edit to wpautop() and the html served to the page is identical to the html I pasted into the code view window.

    BTW, the “fix” is to put return $pee; as the first line in that function, bypassing all of the replaces.

    nevermind … that function is actually used for the OUTPUT of the html to the posts and pages from the DC, too. 😛

    OK, I think this hack works…

    In wpautop()… here are my snippets:

    Initially, I removed any <P> tags in the document since they’ll be replicated by the wpautop() function…

    function wpautop($pee, $br = 1) {
    	//ckck did these two
    	$pee = preg_replace('|<p>|', "", $pee);
    	$pee = preg_replace('|<P>|', "", $pee);
    	//--end ckck

    and then at the end I did this:

    //ckck did this: strip any leading pee
    	if( stripos( $pee, "<P>") < 6 ) {
    		$pee = substr( $pee, stripos( $pee, "<P>" )+3 );
    	$pee = "\n<!-- begin content spooled from db -->\n".$pee."\n<!-- end content spooled from db -->\n";

    I check to see if there is a <P> and the i in stripos means case-insensitive and then remove it.

    I wish I knew regex (regular expressions) better. There is a lot of code in this function, but I think they juuust missed the mark with their conditions. I bet a couple “simple” edits to the pattern matching by a seasoned regex grand wizard would fix it without my hacks.

    Also, using some of PHP’s str functions instead of preg_replace() would make this execute far less code.

    Oh wow… this it the fix:

    This gentleman has enabled a rich text editor to work as a plug in with WP.

    NOTE: you leave the rich text editor disabled … this one shows up when you go to edit a page. It has a lot of functions, but it definitely didn’t do that weird “P” thing all over my html. 🙂 It also left my <div id=”red-box”> alone, which WP+TinyMCE couldn’t do. 🙂 🙂

    i’ve tried that xinha editor and it really seems to do the proper job.
    i will need to try it with more complex html and if it still works good.
    thanks for sharing this 🙂

    @ cacycleworks: it’s not “the fix” as xinha doesn’t work in safari 🙁

    as mentioned in this post highlighting your post and clicking the “align text left” button seems to work (tried it) but it’s is a hassle that should be redundant… I don’t understand how an issue like not being able to have paragraphs hasn’t been fixed a long time ago! I mean how do people write their blogs without paragraphs?! And clearly not everyone knows about the text-align button thing (which is retarded anyways).

    I don’t consider this a whinge post, more a irritated plea for the absurdly obvious to be fixed…

    Wonder if Moveable Type does this sort of thing…

    i’ve finally solved this problem using the wymeditor plugin:

    Simple WYMeditor



    There’s a great plugin which wraps code with a comment to prevent the code from being altered by the html editor. It’s at and works in 2.6.2.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘wp screwed the html code’ is closed to new replies.