comment_form_defaults
云策文档标注
概述
comment_form_defaults 是一个 WordPress 过滤器,用于修改评论表单的默认参数。开发者可以通过此过滤器自定义表单的标题、字段等设置,以适配特定主题或功能需求。
关键要点
- 这是一个过滤器,允许修改评论表单的默认参数数组 $defaults。
- 常用于主题的 functions.php 文件中,通过 add_filter 挂钩来应用自定义设置。
- 可修改的参数包括 title_reply、fields、comment_field 等,具体列表在文档中提供。
代码示例
function wpdocs_set_comment_form_defaults( $defaults ) {
$defaults['title_reply'] = __( 'Add a Comment' );
return $defaults;
}
add_filter( 'comment_form_defaults', 'wpdocs_set_comment_form_defaults' );
原文内容
Filters the comment form default arguments.
Description
Use ‘comment_form_default_fields’ to filter the comment fields.
Parameters
$defaultsarray-
The default comment form arguments.
Source
$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
Skip to note 3 content
designerthan
The following defaults are possible to set with this code:
function wpdocs_set_comment_form_defaults( $defaults ) { //Here you are able to change the $defaults[] //For example: $defaults['title_reply'] = __( 'Add a Comment' ); return $defaults; } add_filter( 'comment_form_defaults', 'wpdocs_set_comment_form_defaults' );Possible values for $defaults[ ‘…’ ]:
Skip to note 4 content
jqz
Example for overriding the title of the comment form (default ‘Leave a Reply’) from within a theme’s functions.php in the theme setup function:
function wpdocs_comment_form_defaults( $defaults ) { $defaults['title_reply'] = __( 'Add a Comment' ); return $defaults; } add_filter( 'comment_form_defaults', 'wpdocs_comment_form_defaults' );