Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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):

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

I do not want WP Editor to strip such attributes.

Any Help ?

share|improve this question
add comment

2 Answers

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

share|improve this answer
add comment

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!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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