如何将自定义属性添加到Wordpress wp_editor文本区域?

时间:2016-12-21 05:35:23

标签: wordpress wp-editor

如何向Wordpress wp_editor textarea字段添加自定义属性?

在官方文档中,没有办法做到这一点。我需要将客户端验证属性(data-bvalidator =“required”)添加到由WordPress的 wp_editor 方法生成的文本区域。

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

我认为在wp_editor()

中无法添加自定义属性

因此,您需要使用text-area

JQuery字段中添加自定义属性

首先将额外的类添加到编辑器text-area

$settings =   array(
    ......
    'editor_class' => 'customclass_for_addattr',
    ......
);
wp_editor( $content, $editor_id, $settings  ); 

在wp_editor()函数之后添加以下jQuery代码。它使用jQuery text-area方法

将自定义属性添加到atrr
<script type="text/javascript">
   jQuery(document).ready(function(){
      jQuery(".customclass_for_addattr").attr('data-bvalidator','required');
   });
</script>