Support » Fixing WordPress » Why does WP put pre tags in paragraphs?

  • Let’s say I have a post with a block of code between two paragraphs. Here’s what I see in the editor (WYSIWYG is disabled):

    first paragraph text
    <pre>do shell script</pre>
    second paragraph text

    When I publish the post, it turns to

    <p>first paragraph text</p>
    <p><pre>do shell script</pre></p>
    <p>second paragraph text</p>

    This is bad because XHTML doesn’t allow including PRE (and other block-level elements in P tags.
    If I try to remove extra line breaks between paragraphs and code, on the post page I get such markup:

    <p>first paragraph text<br />
    <pre>do shell script</pre><br />
    second paragraph text</p>

    .. which is not better.

    Has anybody faced this issue? Is there a way to make WordPress generate valid markup in such cases without hacking its core files?


Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi

    The wp-unformatted plugin lets you turn off on a post by post basis WP’s tendency to wrap things in <p></p>. You must read the instructions.
    Although it says only tested through 2.1, it works fine in 2.7.1

    Thanks for the tip.

    The interesting thing is that when installed this plugin I couldn’t get it to work. It was very surprising because it’s pretty clear and simple. I thought it may be not working because of one of my other plugins, which improves typography (Typo Lite). When I disabled this plugin, not only WP unformatted started to work, but also the issue with incorrect wrapping of P and CODE was gone. So, I’ll contact the author of the plugin and ask him to fix it.

    Thanks again )

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Why does WP put pre tags in paragraphs?’ is closed to new replies.