WordPress Strips Classnames, And How To Fix It

WordPress 2.0 introduced some sophisticated HTML inspecting and de-linting courtesy of kses.

kses is an HTML/XHTML filter written in PHP. It removes all unwanted HTML elements and attributes, and it also does several checks on attribute values. kses can be used to avoid Cross-Site Scripting (XSS), Buffer Overflows and Denial of Service attacks.

It’s a good addition, but it was also removing the class names from some of the elements of my posts. The result is that the following structured XHTML was coming through without any structure.

<ul class=“fullrecord”>
<li class=“title”><h3>Title</h3>
<ul>
<li>The Effects Of A Modified Ball In Developing The Volleyball Pass And Set For High School Students</li>
</ul>
</li>
<li class=“attribution”>...

Without the semantic value of the classnames, the XHTML loses all the microformatting, making it not only less re-usable/remixable but also harder to style.

<ul>
<li><h3>Title</h3>
<ul>
<li>The Effects Of A Modified Ball In Developing The Volleyball Pass And Set For High School Students</li>
</ul>
</li>
<li>...

A WordPress form post pointed me to the includes/kses.php file, where the $allowedposttags array set the standards for the acceptable tags and attributes. It begins like this:

$allowedposttags = array ('address' => array (), 'a' => array ('href' => array (), 'title' => array (), 'rel' => array ()...

It’s a hack, but changing the entries for some of the tags got me through.

'ul' => array ('class' => array())

WordPress, strip tags, kses, code, fix, hack, class names, semantic markup

6 Responses to “WordPress Strips Classnames, And How To Fix It”

  1. So this is why WP stripped out so many classes and IDs when I switched platforms and imported my old MT posts? Good to know. Man, that pissed me off, but by the time I’d realized what happened it seemed too late to go back and try again. Besides, I had no idea how to fix it.

  2. Yeah, it’s pretty frustrating when you don’t know what’s going on. And only a little less frustrating once you do.

    Still, it helps those who don’t know what they’re doing (and those who do, but have malicious intent) from breaking things.

  3. WordPress should replaces their kses code with the code used in this modified version of kses — http://sourceforge.net/tracker/index.php?func=detail&aid=1752954&group_id=81853&atid=564260

    The modified kses produces better HTML, fixes bugs, allows CSS usage, etc.

  4. woo hooo. that totally worked!

Trackbacks

User contributed tags for this post:

wordpress kses (39) - Wordpress strips html (18) - php filter (17) - wordpress allowedposttags (17) - wordpress strips code (16) - wordpress strip html (16) - Wordpress stripping HTML (13) - wordpress strips css (10) - wordpress strip tags (10) - wordpress (9) - kses.php wordpress (8) - kses wordpress (8) - wordpress kses.php (8) - wordpress removes html (8) - class (7) - allowedposttags (7) - wordpress xmlrpc strip tags (7) - wordpress strip code (7) - wordpress $allowedposttags (6) - wordpress stripping CSS (6) - wordpress strips classes (6) - wordpress strips tags (6) - wordpress strip (6) - wordpress avoid strip tag (5) - wordpress strips class (5) - wordpress strip class (4) - NH STATE STATUE 261:148 (4) - wordpress strips style attribute (4) - wordpress removes html tags (4) - wordpress html filter (4) - wordpress strips html tags (4) - allowedposttags style (4) - wordpress stripping tags (4) - wordpress strip style tag (4) - wordpress strips style (3) - wordpress strips id (3) - wordpress strips a (3) - wordpress kses style (3) - wordpress remove html filter (3) - wordpress stripping css class (3) - wordpress kses plugin (3) - wordpress strips classnames and how to fix it (3) - wordpress strips (3) - php strip tags hack (3) - $allowedposttags (3) - wordpress filter kses (3) - wordpress strips attributes (3) - kses buffer wordpress (3) - wordpress post removes html (3) - wordpress strips html from posts (3) - RSA 261:148 (3) - php strip html attributes (3) - wordpress strips HTML from comments (3) - wordpress class (2) - wordpress strip word markup (2) - wordpress KSES -MU (2) - wordpress mu strip html (2) - wordpress stripping style tags (2) - Wordpress removes attribute tag xmlrpc (2) - wordpress xmlrpc removing style (2) - wordpress removes style attribute (2) - wordpress code stripping form (2) - kses.php CSS (2) - wordpress strips css classes (2) - wordpress strip html fix bug (2) - kses html wordpress (2) - wordpress rss strips html (2) - wordpress strip style tags (2) - wordpress strips classes from posts (2) - wordpress stripping out html tags (2) - replacing kses.php fixed the problem (2) - wordpress stripping attributes (2) - wordpress strips  (2) - wordpress remove html tags (2) - wordpress archive strips out html (2) - word press strips tags (2) - wordpress stripping form (2) - wordpress html strip (2) - wordpress post by email a href (2) - html striping wordpress (2) - wordpress plugin strip tags (2) - php strip attributes (2) - new hampshire registration statute 148 (2) - wordpress kses fix (2) - wordpress removes html from post (2) - wordpress stripping classes from tags (2) - wordpress editor strips out html (2) - wpmu kses disable (2) - xml-rpc stripping < (2) - wordpress disable kses (2) - wordpress stripping html tags (2) - wordpress stripping classes (2) - wordpress strips my HTML (2) - F (2) - wordpress stripping li tags in post (2) - wordpress feed strips html (2) - kses plugin (2) - wordpress mu html filter (2) - wordpress removes IDs and classes (2) - wpmu $allowedposttags (2) - wordpress strips class tags (2) - wordpress strips class attributes (2) - wordpress striptags (2) - NH RSA 261:148 (2) - wordpress stripping tags fix (2) - wordpress classes (2) - wordpress 3.2 strips html (2) - wordpress stripping class (2) - kses (2) - wordpress xmlrpc stripping html tag (1) - xmlrpc stripping <> (1) - WordPress strips all HTML (1) - wordpress kses strip class tags (1) - fix html code wordpress (1) - wordpress removes styles (1) - wordpress strip word xml (1) - wordpress category strip class (1) - site do mu strips (1) - wordpress strips www. (1) -