I'm having a hard time getting wp_kses to allow the class for an input. These approaches didn't work:

input'    => array( 
  'type'  => true, 
  'class' => true, 
  'name'  => true, 
  'value' => true, 
  'id'    => true 

also with array() for class it still is not returned.

Checked is also filtered.

Why do I need this? Well, long story short, the input is in a table which needs to be escaped prior to being printed with echo or with ajax.

  • for example: return array('table' => array( 'class' => true, 'id' => true ), 'input' => array( 'type' => true, 'class' => true / array(), 'name' => true, 'value' => true, 'id' => true ) for table the class is preserved, for input it is not
    – Alex C
    Commented Jan 2, 2017 at 13:29

1 Answer 1


According to the codex, you should define your wp_kses list of allowed html elements as below with array() instead of true

$allowed_html = array(
    'input' => array(
        'type'      => array(),
        'name'      => array(),
        'value'     => array(),
        'checked'   => array()
  • If only you had read my question
    – Alex C
    Commented Jan 2, 2017 at 13:30
  • From [core.trac.wordpress.org/browser/tags/4.5.3/src/wp-includes/… class and id are already defined in the allowed global attributes. Not sure why it isn't working for you
    – Tunji
    Commented Jan 2, 2017 at 14:01
  • Thanks, your observation saved the day! My mistake was a missing space that I didn't notice and was being printed right next to the class, like: <input type="checkbox" class="myclass"checked> and this of course was invalidating the attribute. It was a corner case obviously.
    – Alex C
    Commented Jan 2, 2017 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.