WordPress.org

Ready to get started?Download WordPress

Forums

Order of P and Div (22 posts)

  1. malcolmcoles
    Member
    Posted 5 years ago #

    I have this issue with the order of P and Divs when I add an image. It seems to be mucking up the design. This is what some typical HTML looks like:

    <p>
    <div id="attachment_2045" class="wp-caption aligncenter" style="width: 500px"><img class="size-full wp-image-2045" title="new-sprite-google" src="http://www.malcolmcoles.co.uk/blog/wp-content/uploads/2009/04/new-sprite-google.png" alt="New google sprite (left); old google sprite (right)" width="490" height="191" />
    <p class="wp-caption-text">New google sprite (left); old google sprite (right)</p>
    </div>
    </p>

    (from http://www.malcolmcoles.co.uk/blog/new-google-sprite-july-2009/)
    I thought divs weren't allowed in <p>s?

    It's gone even odder on other pages:

    <p>
    <div id="attachment_1943" class="wp-caption aligncenter" style="width: 502px"><img class="size-full wp-image-1943" title="bbc-ashes-2005" src="http://malcolmcoles.co.uk/blog/wp-content/uploads/2009/04/bbc-ashes-2005.png" alt="Query deserves 4 years ago?" width="492" height="203" /><p class="wp-caption-text">Query deserves 4 years ago?
    </p>
    </div>
    <br />
    Update: It's taking it from the DMOZ entry according to the comment below. Odd behaviour ...
    <div class="tweetmeme_button" style="float: right; margin-left: 10px;">

    That one has got a whole chunk of text not in a <p> ... The bit beginning Update.

    Anyone got any clues on what causes this?

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    I thought divs weren't allowed in <p>s?

    They're not.

    Anyone got any clues on what causes this?

    Some custom code or function in single.php by the looks of it.

  3. malcolmcoles
    Member
    Posted 5 years ago #

    I've had a hunt round and I can't see anything obvious. Got any clue what I should be looking for? Is it likely to be some image related thing in the functions file, for instance?

  4. esmi
    Forum Moderator
    Posted 5 years ago #

    Yes - I'd check through functions.php

  5. Jauhari
    Member
    Posted 5 years ago #

    This is new featured of WordPress 2.6 and newer, to disable the <DIV is simple, just don't put any text on Edit Image Caption field
    Screen Shot
    Best Regards

    Jauhari

  6. esmi
    Forum Moderator
    Posted 5 years ago #

    This is new featured of WordPress 2.6 and newer

    Sorry? I'm currently running 2 separate WP 2.8.2 dev installs and neither shows this invalid nesting with captioned images. I've also checked on a client's 2.7.1 install. The code is valid there too.

    It's not a feature of 2.6x at all (see wp-includes/media.php). It could be an issue with some themes that have re-written the caption shortcode via the functions.php file but that has nothing to do with WP itself.

  7. malcolmcoles
    Member
    Posted 5 years ago #

    I'd quite like to keep the captions! And I've seen other installs, as esmi says, without the invalid nesting. I've hunted through functions.php, and can't see any reference to captions in there.

    I added:
    remove_filter('the_content', 'wptexturize');
    remove_filter('comment_text', 'wptexturize');
    But I can't see why this would cause it?

  8. malcolmcoles
    Member
    Posted 5 years ago #

    Also, I've just put an image in and nothing else and previewed. I get this:

    <p>
    <div id="attachment_2045" class="wp-caption aligncenter" style="width: 500px">
    <img src="xxxx.png" alt="xxxx" title="xxx" width="490" height="191" class="size-full wp-image-2045" />
    <p class="wp-caption-text">xxx</p>
    </div>

    I don't think it's the caption causing the problem - the caption <p>s are within the div.
    But a rogue <p> has appeared before the div - with no closing p

  9. malcolmcoles
    Member
    Posted 5 years ago #

    OK, is it related to wpautop?

    This sounds like a similar problem: http://wordpress.org/support/topic/280790

  10. malcolmcoles
    Member
    Posted 5 years ago #

    OK, I'm now talking to myself a lot. But here is another example, which someone solved by disabling a plugin that I don't use:
    http://wordpress.org/support/topic/189740?replies=11

    So, I think we can conclude that it isn't the theme or wordpress core, but possibly a plugin. Er, I don't have any obvious plugins that would cause this. Sigh.

  11. esmi
    Forum Moderator
    Posted 5 years ago #

    Have you tried switching to the default theme? I'm 99% sure it's theme-related.

  12. malcolmcoles
    Member
    Posted 5 years ago #

    Hi, esmi. That was a good idea ... but the problem remains - the code stays as it was (with the divs inside the <p>s)

  13. esmi
    Forum Moderator
    Posted 5 years ago #

    Do you have any plugins installed? Even inactive ones?

  14. malcolmcoles
    Member
    Posted 5 years ago #

    You're going to suggest turning them all off aren't you ...

    I have these active:
    Akismet
    AYB Javascript In Posts
    DoFollow
    Get Recent Comments
    Redirection
    ShareThis
    Subscribe To Comments
    TweetMeme Button
    Twitter Tools

    And these inactive:
    Hello Dolly
    WP Automatic Upgrade
    WP Database backup

  15. esmi
    Forum Moderator
    Posted 5 years ago #

    Yep. :-)

    And if that doesn't work, the next steps are to rename the plugins folder via FTP, then use PhpMyAdmin to reset the plugin folder name in the database to confirm that there's absolutely no plugin involvement.

  16. malcolmcoles
    Member
    Posted 4 years ago #

    So, I never did solve this. Esmi - I don't really want to poke about in my database with phpmyadmin if I can avoid it. Are there any other possibilities you can think of? I've tried no plugins and the default theme. But the problem persists as you can see in my latest post:
    http://www.malcolmcoles.co.uk/blog/im-a-celebrity-2009-itv-seo
    The code in there looks like this:

    <p><div id="attachment_3457" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-3457" title="im-a-celebrity-2009-gmooh" src="removed" alt="I'm a Celebrity 2009 results" width="300" height="275" /><p class="wp-caption-text">I'm a Celebrity 2009 results</p></div></p>

    (I took the src out to shorten the code!)

  17. essday
    Member
    Posted 4 years ago #

    I'm having the same problem too on my self-hosted blog (running the current WP 2.8.6).

    As a real kicker, I even got it to break as you described with the WordPress MU installation running at WordPress.com!

    So given the above, it's not just you, and I will speculate that it's not (directly) the fault of your plugins or themes!

  18. malcolmcoles
    Member
    Posted 4 years ago #

    Essday - I have noticed a new quirk of this which is that the closing <p> is missing from my posts as well - ie the last paragraph of the actual content (before the comments area etc) has a beginning <p> but no closing one. Does yours do that too?

    EG if you go to my link above, the code looks like this at the end of the post:

    <p>Well, at least they're honest (if poor spellers)!
    <div class="tweetmeme_button" style="float: right; margin-left: 10px;"><iframe src="http://api.tweetmeme.com/button.js?url=http%3A%2F%2Fwww.malcolmcoles.co.uk%2Fblog%2Fim-a-celebrity-2009-itv-seo%2F&source=malcolmcoles&style=normal&service=bit.ly" height="61" width="50" frameborder="0" scrolling="no"></iframe></div>
    <h5> Etc Etc

    As you can see, the h5 kicks in - but the p hasn't closed ...

  19. malcolmcoles
    Member
    Posted 4 years ago #

    But I want a caption for my images! Is there no way to have a caption and valid HTML? I'm sure I've seen examples of this ...

  20. essday
    Member
    Posted 4 years ago #

    I'm sure it *should* be possible without broken tags, but I think a bug in WordPress is preventing this from happening.

    If somebody here has the time, we need to file an actual bug report so that the developers see it. This probably involves creating a set of instructions to make it break starting from a known-good setup. Perhaps the WordPress MU installation on WordPress.org is the easiest place to do this.

    Is anyone interested in doing this? (I'm afraid that I don't have a lot of free time right now!)

  21. malcolmcoles
    Member
    Posted 4 years ago #

    Essday: I'd be tempted if I knew it would work. But Esmi (above) says that he doesn't see this bug on his wordpress installs ... Not sure what he's doing that we're not :(

  22. essday
    Member
    Posted 4 years ago #

    OK. I was able to repro the issue myself on a base 2.9.1 install with no plugins and the default theme. The ticket is here. We'll see what happens!

Topic Closed

This topic has been closed to new replies.

About this Topic