WordPress can be an incredible pain in the ‘p’ tag…

I decided to go check that the frontpage of the blog still passed the W3C XML validator today (something I try to remember to do at least semi-regularly) and, to my dismay, there were validation failures all over the place.

It seems that WordPress is not particularly intelligent about determining where it should and should not place <p> tags; depending on how you place your whitespace around the beginning of a list (ol/li) or tt (or other tag whose contents tend to span multiple lines), it seems to have quite an affinity for either spewing completely bogus open or close p tags (or closing tags in the wrong order, such as a opening a p tag before a user-specified li tag, then “helpfully” automagically closing the p tag before the closing li tag the user writes in the post).

The worst part of the whole thing is that the breaking tags are autogenerated, and they’re controlled by what sort of whitespace (e.g. blank lines) you have near your the opening and closing tags. Because the “helpful” autogenerated tags aren’t visible at “design time” for a post, you’re all but limited to blind trial and error to get it working right. Sometimes, you even need to put seemingly bogus </p> tags in at “design time” to match unbalanced tags emitted by WordPress automagically at display time.

I love how this turns writing blog posts that render properly into debugging something that is influenced by how I use whitespace. Argh!

Excuse me, while I go back to figuring out the right combination of blank lines to fix the rest of the blog’s tag close mismatch failures…

3 Responses to “WordPress can be an incredible pain in the ‘p’ tag…”

  1. You want TextControl and Markdown/SmartyPants. Whatever format you write in email messages will probably produce beautiful HTML in Markdown.

    http://dev.wp-plugins.org/wiki/TextControl

  2. Skywing says:

    Thanks; I’ll give it a look. Hopefully, not quite so brain-dead as the built-in formatting…

  3. Mike says:

    Did you find a solution for this issue?

    I just noticed it.

Leave a Reply