• Hi,

    I’m having some problems with WordPress’s automatic paragraph formatting. When I have a self closed image tag followed on the next line by any content (all enclosed in a div) WordPress inserts a paragraph close tag after the image on viewing.

    So this:

    <div>
    <img src="sample_image.jpg" width="240" height="240" alt="Sample" />
    <h1>Sample Header</h1>
    </div>

    Becomes this:

    <div>
    <img src="sample_image.jpg" width="240" height="240" alt="Sample" /></p>
    <h1>Sample Header</h1>
    </div>

    I thought it might be a problem with the ‘wpautop’ function, so I updated that with code from 2.2 but it made no difference. Could it be something to do with tag balancing?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter triffid

    (@triffid)

    Well, I’ve just added the following line to the wpautop function for now. If anyone can suggest a better solution that would be really helpful.

    $pee = preg_replace('|(<[^p]*>\s?<img[^>]*\s/>)</p>|','$1', $pee);

    I have noticed the same (or a similar) problem – except that it seems that WP 2.2 is occasionally inserting both opening and closing paragraph tags, which is definitely not a good idea, considering the frequency with which img elements are wrapped in other block-level elements (like div), floated, positioned, or are otherwise not semantically connected to a text paragraph. Sometimes it happens, and sometimes it doesn’t. I’m a little short on time to test things; otherwise I’d like to file a bug report – but if anyone beats me to it, I won’t be upset.

    For an example, go to my wedding site and search the source for “fixedleft” (auto-wrapped in p tags) and “fixedright” (not wrapped). The img element that is wrapped is the first line of my page content, which is called in the page template by the_content(), so it may be that the_content()‘s output is sent through wpautop or wptexturize or whatever separately from the rest of the page content. I’m not sure. At any rate, I am firmly in the “never auto-wrap img elements with paragraph tags” camp.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP inserts paragraph close tag after self closed image tag’ is closed to new replies.