钩子文档

comment_form_field_comment

💡 云策文档标注

概述

comment_form_field_comment 是一个 WordPress 过滤器,用于修改评论表单中文本区域字段的显示内容。它允许开发者自定义或替换默认的评论输入框。

关键要点

  • 这是一个过滤器钩子,应用于 comment_form() 函数中的评论文本区域字段。
  • 参数 $args_comment_field 是一个字符串,代表评论文本区域的当前内容。
  • 通过 add_filter() 添加回调函数来修改内容,例如清空或自定义文本。

代码示例

function ardeya_textarea() {
    $comment_field = '';
    return $comment_field;
}
add_filter( 'comment_form_field_comment', 'ardeya_textarea' );

注意事项

  • 此过滤器自 WordPress 3.0.0 版本引入,确保在兼容版本中使用。
  • 回调函数应返回一个字符串,以替换或修改原始评论字段内容。

📄 原文内容

Filters the content of the comment textarea field for display.

Parameters

$args_comment_fieldstring
The content of the comment textarea field.

Source

echo apply_filters( 'comment_form_field_comment', $field );

Changelog

Version Description
3.0.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    function ardeya_textarea() {
    	$comment_field = '<textarea id="comment" placeholder="' . esc_attr__( 'Напишите комментарий', 'ardeya' ) ) . '" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea>';
    	return $comment_field;
    }
    add_filter( 'comment_form_field_comment', 'ardeya_textarea' );