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

Related:

4 Comments

  1. Comment by Steve Lawson on May 15, 2007 5:18 pm

    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. Comment by Casey on May 16, 2007 9:42 pm

    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. Comment by Alpha on August 13, 2007 4:43 pm

    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. Comment by dieselboi on March 6, 2008 12:30 am

    woo hooo. that totally worked!

Comments RSS TrackBack Identifier URI

Leave a comment

 

User contributed tags for this post:

wordpress kses (24) - php filter (17) - wordpress strip html (12) - sexytv.1 (9) - wordpress allowedposttags (9) - fix.89.com (7) - class (7) - wordpress strips code (6) - FİX 89.COM (6) - Wordpress strips html (5) - www.fix porno.com (5) - wordpress strips css (5) - wordpress strips classes (5) - wordpress (5) - kses wordpress (5) - wordpress strip (5) - allowedposttags style (4) - wordpress strip style tag (4) - allowedposttags (4) - wordpress strips a (3) - wordpress kses style (3) - wordpress kses.php (3) - wordpress strips (3) - php strip tags hack (3) - Wordpress stripping HTML (3) - fix porno (3) - kses buffer wordpress (3) - wordpress classes (2) - wordpress strips css classes (2) - wordpress stripping CSS (2) - Wordpress removes attribute tag xmlrpc (2) - kses plugin (2) - wordpress stripping classes from tags (2) - wordpress kses fix (2) - wordpress strip html fix bug (2) - wordpress feed strips html (2) - wordpress removes html (2) - wordpress post by email a href (2) - wordpress KSES -MU (2) - wordpress class (2) - wordpress strips my HTML (2) - replacing kses.php fixed the problem (2) - sexytv.1. (2) - wordpress kses plugin (2) - wordpress code stripping form (2) - wordpress strips  (2) - wordpress strips style (2) - wordpress strip tags (2) - wordpress stripping tags fix (2) - wordpress striptags (2) - wordpress strips tags (2) - F (2) - word press strips tags (2) - wordpress strips HTML from comments (2) - kses (2) - wordpress plugin strip tags (2) - sexytv 1 (2) - wordpress strips class attributes (2) - php strip word attributes (1) - wordpress strips tags from feed (1) - Strip XHTML tags (1) - cache 2gMvSr6rBa0J maisonbisson com blog post 10923 sex (1) - remove wordpress html filter (1) - wordpress fix xhtml (1) - wordpress $allowedposttags; (1) - wordpress strip out tags (1) - wordpress html tags in comments (1) - wordpress strip title tags (1) - kses wordpres (1) - wordpress strips styles (1) - cache ZntlthPDIkQJ maisonbisson com blog post 10636 sex (1) - wordpress mu filtered html (1) - www. fix 89.com (1) - fix html in wordpress posts (1) - wordpress hacking kses (1) - wordpress remove html tags (1) - strip on wordpress (1) - wp strip ad (1) - wordpress stripping out form tag (1) - fix.sex.com (1) - wordpress strips out css (1) - wordpress strips html from posts (1) - 18 fix sex.com (1) - www.wierd pisses (1) - wordpress /category.html (1) - post to wp blog email don't strip html (1) - strip classes html (1) - strip tags library php (1) - php strip all html attributes (1) - wordpress strips javascript (1) - $allowedposttags kses (1) - 8204012489985 (1) - wordpress 2 2 array (1) - wordpres kses.php hack (1) - fix porno.com (1) - strip tags from word (1) - wordpress stripping form (1) - wordpress strip ad (1) - wordpress dont fix html (1) - wordpress strips html on tags archive categories (1) - wordpress problem kses (1) - fix 89 (1) - wordpress strip forms (1) - sexytv (1) - wordpress blog stripping out href (1) - ul sex.com (1) - wordpress strip name attribute (1) - form loses name wordpress tinymce (1) - sexe pono (1) - wordpress striping html code from posts (1) - wordpress html form strip (1) - wordpress kses allow javascript (1) - wordpress removes html tags (1) - strips out href (1) - wordpress filters strip tag (1) - wordpress strips out (1) - wordpress strip markup (1) - css strips (1) - fıx.89 (1) - wordpress post removes html (1) - wordpress strips attributes (1) - wordpress removes markup (1) - cache V91dmCAQbdgJ maisonbisson com blog post 10927 CHI (1) - change wp mail in wordpress to not strip tags (1) - cache TCkIBg5aD28J maisonbisson com blog post 10981 xxx (1) - wordpress 2.6 strips category names (1) - wordpress comment kses (1) - why does wordpress strip code from my post? (1) - effects of cellphones to students (1) - css attributes for a category wordpress (1) - wordpress category html tag stripped (1) - www fix 89 com. (1) - how to php strip tags wordpress (1) - why does wordpress strip html? (1) - wordpress style tag converted (1) - wordpress kses strip class tags (1) - filtered html tags in wordpress comments (1) - www fix 89,com (1) - wordpress stripping forms (1) - wordpress xmlrpc strip tags (1) - better wordpress kses (1) - wordpress strips css from post (1) - wordpress strips html tags (1) - avoid wordpress stripping html attributes (1) - wordpress email html stripping (1) - wordpress strip code (1) - kses wp OR wordpress japanese attributes (1) - alt OR title attribute kses php wp OR wordpress (1) - wordpress strip tags from posts (1) - kses hack wordpress (1) -