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 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 Bisson 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!

  5. Pingback by Unfilter MU’s Filters | Page 2 on October 8, 2008 12:02 am

    [...] and Flash embeds. This would be fine if it were configurable, but sadly it is not. Various hacks exist to remedy the situation, but for such a pluggable piece of software as WordPress - hacks just seem [...]

  6. Pingback by Data Unbound » How WordPress Sanitizes Tags and Attributes on October 29, 2008 3:51 pm

    [...] in my span HTML elements. To fix the problem, I followed the trail of references leading from » WordPress Strips Classnames, And How To Fix It MaisonBisson.com. I learned that WordPress uses the kses PHP library to filter HTML of possibly invalid and [...]

Comments RSS TrackBack Identifier URI

Leave a comment

 

User contributed tags for this post:

fix porno (41) - wordpress kses (29) - fix.89.com (22) - www.fix porno.com (19) - php filter (17) - wordpress strip html (14) - sexytv.1 (13) - fix 89 (12) - FİX 89.COM (11) - wordpress allowedposttags (10) - www.fix.porno.com (9) - fixporno (9) - Wordpress strips html (8) - FİX.PORNO (8) - wordpress (8) - wordpress strips code (7) - kses wordpress (7) - class (7) - wordpress strips css (7) - fix porno.com (7) - fix 89 porno (7) - wordpress strip (6) - wordpress strips classes (5) - Wordpress stripping HTML (5) - wordpress avoid strip tag (5) - wordpress removes html (4) - fıx.89 (4) - allowedposttags (4) - wordpress strip style tag (4) - allowedposttags style (4) - wordpress $allowedposttags (3) - facebookofsex.com (3) - wordpress kses.php (3) - www.fixporno.com (3) - wordpress kses style (3) - wordpress strip tags (3) - wordpress strips (3) - sexytv 1 (3) - php strip tags hack (3) - wordpress strips a (3) - php strip html attributes (3) - kses buffer wordpress (3) - wordpress strips class attributes (2) - wordpress mu html filter (2) - html striping wordpress (2) - kses (2) - wordpress kses fix (2) - fix porna (2) - php strip attributes (2) - www.fix.89 (2) - wordpress mu strip html (2) - wordpress strip word markup (2) - wordpress strips style (2) - wordpress kses plugin (2) - sexytv.1. (2) - wpmu $allowedposttags (2) - wordpress xmlrpc strip tags (2) - wordpress stripping tags fix (2) - wordpress striptags (2) - wordpress strips  (2) - wordpress classes (2) - wordpress strips style attribute (2) - kses plugin (2) - replacing kses.php fixed the problem (2) - wordpress html filter (2) - wordpress stripping CSS (2) - wordpress stripping classes from tags (2) - wordpress rss strips html (2) - wordpress strips tags (2) - word press strips tags (2) - wordpress strips HTML from comments (2) - kses html wordpress (2) - wordpress KSES -MU (2) - wordpress strip html fix bug (2) - wordpress strips css classes (2) - F (2) - fixs porno (2) - wordpress class (2) - www,fix.porno.com (2) - Wordpress removes attribute tag xmlrpc (2) - wordpress strips my HTML (2) - wordpress post by email a href (2) - wordpress plugin strip tags (2) - kses.php CSS (2) - wordpress archive strips out html (2) - wordpress feed strips html (2) - xml-rpc stripping < (2) - wordpress removes IDs and classes (2) - 89porno (2) - wordpress code stripping form (2) - fixporno.com (2) - wordpress stripping xhtml? (1) - facebookofsex (1) - porno kses (1) - wordpress strip tag bug xmlrpc (1) - wordpress xmlrpc stripping < (1) - wordpress html form tags (1) - wordpress removing name and class from
 (1) - disable kses wordpress mu (1) - wordpress strips html codes (1) - wordpress remove html filter (1) - www. sex amreka (1) - wordpress strips style elements (1) - wordpress remove word html (1) - wordpress dont fix html (1) - strip html attribute php (1) - wordpress strip < (1) - wordpress html class (1) - wordpress stripping attributes (1) - XMLRPC html stripping wordpress (1) - why does wordpress strip my html codes (1) - wordpress xml-rpc stripping tags (1) - where is wordpress html tags strip (1) - www.wierd pisses (1) - wordpress filters remove tags (1) - HTML attributes to strip out of rss (1) - wordpress stripping tags plugin (1) - wordpress strip style tags (1) - php stripword (1) - wordpress stripping out html (1) - wordpress Filter HTML Tags from RSS Feed (1) - wordpress mac bugs tags stripped (1) - wordpress strips style tags (1) - post new article XML-RPC html tags stripped (1) - post new article XML-RPC html tags stripped wordpress (1) - class of sex.com (1) - wordpress strip comment (1) - post by email wordpress remove html tags (1) - comments wordpress filter html (1) - kses remove (1) - wordpress filters attributes html (1) - wordpress filters html attributes (1) - sexepono (1) - wordpress MU strip tag (1) - disable kses.php wordpress (1) - wordpress stripping name attribute (1) - Wordpress XML-RPC stripping (1) - wordpress stripping tags (1) - wordpress comment href stripped (1) - wordpress xmlrpc stripping html (1) - wordpress mu strip tags (1) - Wordpress remove kses filter (1) - wordpress xmlrpc stripping code (1) - wordpress filter strip style attribute (1) - wordpress strips out xhtml? (1) - pàrno strips (1) - sty,porno.com (1) - how to disable wordpress comment styling (1) - fix p o r n e (1) - Wordpress removes 
 (1) -