您应该筛选\'comment_form_default_fields\'
添加placeholder
属性
示例代码
add_filter( \'comment_form_default_fields\', \'wpse_62742_comment_placeholders\' );
/**
* Change default fields, add placeholder and change type attributes.
*
* @param array $fields
* @return array
*/
function wpse_62742_comment_placeholders( $fields )
{
$fields[\'author\'] = str_replace(
\'<input\',
\'<input placeholder="\'
/* Replace \'theme_text_domain\' with your theme’s text domain.
* I use _x() here to make your translators life easier. :)
* See http://codex.wordpress.org/Function_Reference/_x
*/
. _x(
\'First and last name or a nick name\',
\'comment form placeholder\',
\'theme_text_domain\'
)
. \'"\',
$fields[\'author\']
);
$fields[\'email\'] = str_replace(
\'<input id="email" name="email" type="text"\',
/* We use a proper type attribute to make use of the browser’s
* validation, and to get the matching keyboard on smartphones.
*/
\'<input type="email" placeholder="[email protected]" id="email" name="email"\',
$fields[\'email\']
);
$fields[\'url\'] = str_replace(
\'<input id="url" name="url" type="text"\',
// Again: a better \'type\' attribute value.
\'<input placeholder="http://example.com" id="url" name="url" type="url"\',
$fields[\'url\']
);
return $fields;
}
结果
有些注释不使用占位符代替label
. 屏幕阅读器用户会非常生气。确实如此not allowed 无论如何我已经更改了type
属性也是。这将比placeholder
.
确保字段看起来不是已经填写的。但试着得到一个可读的对比。是的,那不容易。你可以use some CSS, 但它并不适用于所有浏览器