使用最新版本的WordPress,我正在处理我的孩子主题。我在特定页面上启用了注释。我可以看到OOTB我启用了作者、电子邮件、网站和评论输入区域。
从我的功能。php位置。我只想隐藏我的网站字段,并更改评论字段的标签,从;“注释”;“到”;留下评论;。我尝试了以下方法,但它隐藏了除“文本区域”框之外的所有内容;留下评论。How can I also bring Author, Email, and Cookie input fields back?
function _ac_comment_fields_custom_order( $fields ) {
$comment_field = $fields[\'comment\'];
$author_field = $fields[\'author\'];
$email_field = $fields[\'email\'];
$url_field = $fields[\'url\'];
$cookies_field = $fields[\'cookies\'];
unset( $fields[\'comment\'] );
unset( $fields[\'author\'] );
unset( $fields[\'email\'] );
unset( $fields[\'url\'] );
unset( $fields[\'cookies\'] );
$fields[\'author\'] = $author_field;
$fields[\'email\'] = $email_field;
$fields = [
\'comment_field\' => sprintf(
\'<p class="comment-form-comment">%s %s</p>\',
sprintf(
\'<label for="comment">%s</label>\',
_x( \'Your Review\', \'noun\' )
),
\'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea>\'
)];
$fields[\'cookies\'] = $cookies_field;
// done ordering, now return the fields:
return $fields;
}
add_filter( \'comment_form_fields\', \'_ac_comment_fields_custom_order\' );
最合适的回答,由SO网友:Q Studio 整理而成
您正在重新声明变量$fields
定义email
键-这基本上删除了所有以前的值-相反,您需要为添加一个新键comment_field
, 例如:
// retain code before..
$fields[\'author\'] = $author_field;
$fields[\'email\'] = $email_field;
$fields[\'comment_field\'] = sprintf(
\'<p class="comment-form-comment"><label for="comment">%s</label><textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p>\',
__( \'Your Review\', \'theme-textdomain\' )
);
$fields[\'cookies\'] = $cookies_field;
// retain code after..
我还减少了你的
sprintf
对于单个函数,由于您只需要使用此函数一次,因此也应该使用自己的函数
text-domain
.