WP 2.1 - Posting Problem (38 posts)

  1. Deny
    Posted 9 years ago #

    I have no idea,
    is this a bug or there is something wrong with the way I post a news.

    I try to insert this code somewhere between my post:

    <div class="blablabla"><hr /></div>

    And, when I saw the result with browser, my Tidy plugin give me a warning alert. There is something wrong with my tag, unneeded <p> tag without closing </p> tag.

    <div class="blablabla"><hr /><p></div>

    And then, I try to fix my post which contain unneeded <p> tag. But, I found more weird result with my post that I'm going to edit (i'm using code tab - not visual).

    the code become: <p class="blablabla"><hr /></p>

    now, that is not funny :D

    I've done enough test about this problem,
    and I'm pretty sure that there is something wrong.
    Sometimes it is ok, sometimes it isn't.

    Now, I don't want to edit my post again - it show me the correct code now.

  2. silence226
    Posted 9 years ago #

    2.1 version tinyMCE will replace <div> by <p> when saving post, you may change this by hacking file: wp-incluede/js/tinymce 的 tiny_mce_config.php
    about 24th line, find:
    $valid_elements = ‘p/-div[*],-strong/-b[*],-em/-i[*],-font[*],-ul[*],-ol[*],-li[*],*[*]’;

    replace by:
    $valid_elements = ‘-strong/-b[*],-em/-i[*],-font[*],-ul[*],-ol[*],-li[*],*[*]’;

    another is "Post Formatting" issue, wordpress will add <p> tag inside the tag <div> when you brows the post,
    so you have to hacking the file: wp-includes/formatting.php
    about 66th line find:
    $pee = preg_replace( ‘|<p>(<div[^>]*>\s*)|’, “$1<p>”, $pee );
    and comment it,

    and it will never append <p> to the <div>

  3. owenkelly
    Posted 9 years ago #

    I had this problem too, and your suggestions fixed it perfectly.

    I have to say though that I am very unhappy modifying core files like this. Not because I don't know what I am doing, but because (when it comes time to upgrade again) I probably won't remember what I have had to do!

    This means I have to document the changes and then remember to reapply them when 2.1.1 arrives.

    What is odd though is that I cannot imagine the logic of this in the first place. Why would you want to change a div into p behind someone's back?

    Anyway many thanks, silence266. I was getting VERY frustrated, and now I am a happy camper :)

  4. adriangab
    Posted 9 years ago #

    Oh thank you so much! This was driving me nuts with the issue of adding p tags.

    All fixed now though. Thanks heaps!

  5. makemead
    Posted 9 years ago #

    What is odd though is that I cannot imagine the logic of this in the first place. Why would you want to change a div into p behind someone's back?

    I agree 100%. Changing div to p will break style sheets. Since there is no purpose for it, I'd say it needs to be nixed.

    At least the trackbacks finally seem to be working. This issue will take its place in my regular complaints. :^D

  6. makemead
    Posted 9 years ago #

    There is some talk about this in trac.

  7. falp
    Posted 9 years ago #

    I made the changes specifed here but now the visual editor is stripping the <p> and </p> tags. So what should be:
    <div id"test"><p>blah blah blah</p></div>

    Is being converted to
    <div id"test">blah blah blah</div>

    This is driving me mad.

  8. Colin_Lewis
    Posted 9 years ago #

    @Falp -

    If you put the <div> on a separate line then you'll get the correct formatting. If you write:

    <div id"test">
    blah blah blah

    then WordPress will place "blah blah blah" within paragraph tags.

  9. mmwp99
    Posted 9 years ago #

    Thanks for this fix!

    The visual editor messed up one of my fairly complex existing posts by replacing <div class=...> with <p class=...> and it took me a couple of hours to figure that out. Argh!

  10. mmwp99
    Posted 9 years ago #

    A newbie tip: you need to clear your browser cache before the tiny_mce_config.php change will take effect.

  11. bostrom
    Posted 9 years ago #

    When I change the $valid_elements variable in tiny_mce_config.php it results in the tinyMCE editor's tabs and toolbars not showing up. All I see is the code of my post in a semi-rendered editor-box...

    Any ideas?

    (Using WP 2.1.2)

  12. freshspace000
    Posted 9 years ago #

    Excellent, this has solved my div problem which was a major headache!

  13. outre99
    Posted 9 years ago #

    I was having the same unwanted tags problem but with un-orthodox code below. This code allows to show pure CSS popups with additional details when a user hovers over the link.

      <a class="thumbnail" href="#"> link text
        <span class="popup">
          <span class="caption"> title </span>
          <img src='.../uploads/2007/04/image.jpg' />
          <p>pop-up description</p>

    I was getting the same dreadful extra <p> tag. But since i'm not using the divs here the mentioned solutions didn't work. I'm not familiar with regex so hacking the formatting.php was not an option. So I added span, a, and img to the $allblocks array in formatting.php. That fixed the <p> problem, but now I'm wondering what is it going to break.
    I understand that the WP usability requires this kind of code filtering and formatting. However, there are times when it is undesirable. Is there a WP specific tag or plugin that would escape a block of code from this processing?

  14. sunburntkamel
    Posted 9 years ago #

    thanks for this. the offending code has now been expanded to:

    $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee);

    (line 63)

    it's not just about breaking stylesheets, it's about validation. formatting isn't good enough, so i wind up with an open <p> and a closing </div>

  15. morktron
    Posted 9 years ago #

    Thanks people that's great.

    I've replaced

    $valid_elements = 'p/-div[*],-strong/-b[*],-em/-i[*],-font[*],-ul[*],-ol[*],-li[*],*[*]';


    $valid_elements = '-strong/-b[*],-em/-i[*],-font[*],-ul[*],-ol[*],-li[*],*[*]';

    but unfortunately now it inserts a linespace if the div tag is at the top of the code.

    Anyway at least now I can have div's - so thanks :)

  16. alexleonard
    Posted 9 years ago #

    I have found that commenting out the line in formatting.php still caused issues (it was using my </div> and not appending a </p> causing markup to fail validation).

    However by just making the suggested change to the tiny mce config that seems to have sorted things for me... for now..

    I am very surprised by this behaviour.

  17. saphod
    Posted 9 years ago #


    Thank you very much for this fix, it works fine with my WP 2.1.3!

    This was SO annoying!


  18. Hulk
    Posted 9 years ago #

    mmwp99, thanks for the tip about clearing my browser cache! I couldn't figure out why this wasn't working.

    I changed the tiny_mce_config.php as directed above, and this solved my problems.

    I couldn't find the offending code in formatting.php. Maybe it's been removed in version 2.2.1 (my current install)

    It would be nice if WordPress didn't change code! This reminds me of using FrontPage back in 1999, when it would attempt to fix things that didn't need fixin'.

  19. NixDesign
    Posted 9 years ago #

    Changing the tiny-mce_config.php file as suggested has also fixed the problem for me but . . .

    . . . in doing so, it's disbled me having the ability to use the Rich Text Editor. The RTE just doesn't appear now when I select a page to edit.

    Now I don't personally need the RTE, but I'm creating a site using WP as a CMS and need to have other people (with no html knowledge whatsoever) be able to use the RTE to edit pages in the future.

    Has anyone else encountered this?

    p.s. I'm using WP version 2.2.1

  20. NixDesign
    Posted 9 years ago #

    Furthermore . . .

    I went back and changed the tiny_mce_config file back to haw it was before and it didn't bring back the RTE, neither did restoring my database in phpMyAdmin.

  21. NixDesign
    Posted 9 years ago #

    Okay - I have the RTE back now after downloading a completely new file, but I'm back to have the same issue with WP changing the <div> to <p>


  22. 44r0ng
    Posted 9 years ago #

    Try using a <span> tag. Similar to the <div> and it doesn't get parsed out.

  23. Erinyes
    Posted 8 years ago #

    I went ahead and removed a lot of the other replacement crap too.

    Did it even occur to the guy who wrote it that some people might not be using Html, xHtml but instead xml and any sort of goof off like that would result in imediate browser error. Sheesh.~

    It must be really hard to put a damn on/off switch somewhere for this kind of time consuming cursed "feature".

  24. JHouse
    Posted 8 years ago #

    I tried removing the undesirable code from the tiny_mce_config.php file (on the latest WP version), and while it worked, I lost edit controls. Meaning, I can't use the included edit features, like Add Link, Bold, Paragraph, or even get to the code source editer. Anybody have a solid solution for the newer WP installations 'cause I think most of the code above was for older versions.

    This code replacement thing is really killing me. How dare they replace my code, I know what I is doing. Dang.

    Any help would be nice.


  25. JHouse
    Posted 8 years ago #

    Oh yeah, I'm using version 2.2.1

  26. apertureboy
    Posted 8 years ago #


    Can someone help? All I want is <div class=""> or <div id=""> or <p class=""> or heck, even <p id="">

    I've made the changes mentioned above to formatting.php and tiny_mce_config as well as adding

    'div' => array ('class' => array ()),
    'p' => array ('class' => array ()), etc to $allowedposttags and $allowedtags in kses.php...but nothing... anyone else have this issue? And a fix?



  27. apertureboy
    Posted 8 years ago #


    Solved the problem I was having. I downloaded the latest kses file http://trac.mu.wordpress.org/browser/trunk/wp-includes/kses.php?rev=1055
    added 'class' => array() to the div and p array and its working in case anyone else has a similar problem with class in the p and div tag


  28. JHouse
    Posted 8 years ago #

    Hey apertureboy,

    What version of WP are you using? I want to give that hack a shot. I guess you're now able to drop in div tags and not have it rewritten by WP?


  29. apertureboy
    Posted 8 years ago #

    Hey JHouse

    Actually Im using Wordpres mu 1.25a. For one install I used the 2 above mentioned hacks and then the latest kses file with class and id added to the arrays. For another install I just replaced the kses file with the new version and added class and id to the arrays and that allowed class and id in divs and p tags


  30. JHouse
    Posted 8 years ago #

    Awesome. Thanks for the info. I'm gonna give the kses file hack a shot.

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic