• 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 ??

    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.

Viewing 15 replies - 1 through 15 (of 37 total)
  • 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>

    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 ??

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

    All fixed now though. Thanks heaps!

    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

    There is some talk about this in trac.

    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.

    @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
    
    </div>

    then WordPress will place “blah blah blah” within paragraph tags.

    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!

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

    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)

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

    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.

    <dt>
      <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>
        </span>
     </a>
    </dt>
    <dd>description</dd>

    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?

    Amie

    (@sunburntkamel)

    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>

    Thanks people that’s great.

    I’ve replaced

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

    with

    $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 ??

    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.

Viewing 15 replies - 1 through 15 (of 37 total)
  • The topic ‘WP 2.1 – Posting Problem’ is closed to new replies.