钩子文档

comment_form_before_fields

💡 云策文档标注

概述

comment_form_before_fields 是一个 WordPress Hook,在评论表单的字段(不包括 textarea)之前触发,允许开发者在这些字段前添加自定义内容或功能。

关键要点

  • 这是一个 action Hook,在 comment_form() 函数中调用,位于评论表单的字段部分之前。
  • 主要用于在评论表单的字段(如姓名、邮箱、网址等)前插入自定义 HTML、脚本或其他元素。
  • 与 comment_form_after_fields Hook 相对应,后者在字段之后触发。

代码示例

add_action( 'comment_form_before_fields', 'my_custom_before_fields' );
function my_custom_before_fields() {
    echo '<div class="custom-notice">请填写以下信息:</div>';
}

注意事项

  • 此 Hook 仅影响评论表单的字段部分,不包括 textarea(评论内容输入框)。
  • 在 WordPress 3.0.0 版本中引入,确保兼容性。
  • 常用于添加验证提示、样式类或动态内容,以增强用户体验。

📄 原文内容

Fires before the comment fields in the comment form, excluding the textarea.

Source

do_action( 'comment_form_before_fields' );

Changelog

Version Description
3.0.0 Introduced.