有没有办法为WordPress Customizer文本输入字段添加占位符

时间:2017-08-09 作者:Kamal Ahmed

我想知道是否可以为WordPress自定义输入字段,特别是文本和文本区域字段添加占位符文本。

我通过下面的代码添加了一个输入控件。谁能告诉我如何将占位符文本添加到输入字段中?

$wp_customize->add_control(\'directorist_address\', array(
            \'label\' => __(\'Address\', \'directorist\'),
            \'section\' => \'directorist_contact\',
            \'settings\' => \'directorist_address\',
            \'description\' => __(\'Enter your contact address. Eg. Abc Business Center, 123 Road, London, England\'),
        )

);
上面的代码输出如下输入字段:

sample text input field in WordPress Customizer without placeholder

但我想在文本输入字段中显示一些占位符文本。谢谢

1 个回复
最合适的回答,由SO网友:Jacob Peattie 整理而成

您可以使用input_attrs 将属性传递给输入的参数:

$wp_customize->add_control(\'directorist_address\', array(
        \'label\' => __(\'Address\', \'directorist\'),
        \'section\' => \'directorist_contact\',
        \'settings\' => \'directorist_address\',
        \'description\' => __(\'Enter your contact address. Eg. Abc Business Center, 123 Road, London, England\', \'directorist\' ),
        \'input_attrs\' => array(
            \'placeholder\' => __( \'Placeholder goes here...\', \'directorist\' ),
        )
    )
);

结束

相关推荐