WP Editor strips input placeholder attribute

Why WP Editor also strips the “placeholder” attribute of the input text element ?
Ofcourse, i am using the HTML mode.
Here is the input:

<input type="text" value="" name="s" style="width: 550px;" placeholder="Search this website..">

After updating the post (after strip):

Read More
<input type="text" value="" name="s" style="width: 550px;">

I do not want WP Editor to strip such attributes.

Any Help ?

Related posts

Leave a Reply

2 comments

  1. The list of allowed elements and attributes is stored in the global variable $allowedposttags which is set in wp-includes/kses.php.

    To override it create a simple mu plugin with the following content:

    <?php # -*- coding: utf-8 -*-
    /**
     * Plugin Name: Enable placeholder attribute for input elements in post tags.
     * Version: 2012.07.18
     */
    
    add_action( 'init', 'wpse_54829_register_placeholder' );
    
    
    function wpse_54829_register_placeholder()
    {
        global $allowedposttags;
    
        $default = empty ( $allowedposttags['input'] ) ? array () : $allowedposttags['input'];
        $custom  = array (
            'placeholder' => TRUE,
            'name'        => TRUE,
            'value'       => TRUE,
            'size'        => TRUE,
            'maxlength'   => TRUE,
            'type'        => TRUE,
            'required'    => TRUE
        );
    
        $allowedposttags['input'] = array_merge( $default, $custom );
    }
    

    This post with the content <input placeholder="pass" required /> was created with an author account:

    enter image description here

  2. You could use a shortcode! 😉

    <?php
    
    // desired output: <input type="text" value="" name="s" style="width: 550px;" placeholder="Search this website..">
    // sc: [text_input name="s" style="width: 550px;" placeholder="Search this website.."]
    
    add_shortcode('text_input','text_input_sc');
    function text_input_sc($atts) {
    
        // modify defaults as you wish
        $defaults = array(
            'id' => null,
            'class' => null,
            'value' => null,
            'name' => null,
            'size' => null,
            'style' => null,
            'placeholder' => null
        );
    
        $args = shortcode_atts($defaults, $atts);
    
        $out = array();
    
        foreach ($args as $attr => $value) {
    
            if ( null !== $value )
                $out[] = $attr.'="'.$value.'"';
    
        }
    
        $out = trim(implode(' ', $out));
    
        if( !empty($out) )
            $out = ' '.$out;
    
        return vsprintf('<input type="text"%s>', $out);
    
    }
    

    Untested, but should definitely work!