Skip to content

Instantly share code, notes, and snippets.

@jesgs
Created September 13, 2013 16:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesgs/8835e2785e019938a0ae to your computer and use it in GitHub Desktop.
Save jesgs/8835e2785e019938a0ae to your computer and use it in GitHub Desktop.
<?php
add_filter('gform_field_content', 'add_placeholder_attr', 10, 3);
/**
* Add a placeholder attribute to text inputs
*
* @param string $content
* @param array $field
* @param mixed $value
*
* @return string
*/
function add_placeholder_attr($content, $field, $value)
{
if ($field['type'] == 'text' || $field['type'] == 'email') {
$label = $field['label'];
$placeholder = "placeholder='{$label}' value='{$value}' ";
$content = str_replace("value='' ", $placeholder, $content);
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment