我想更改我评论表单中的标题“姓名”、“电子邮件”和“网站”?。我该怎么做?我认为在这个领域改变它们是可行的(\'网站\',\'域引用\'),但它没有改变任何东西。任何帮助都将不胜感激。
这是我的评论。php
<?php if ( have_comments() ) : ?>
<h4 id="comments"><?php comments_number(\'No Comments\', \'One Comment\', \'% Comments\' );?></h4>
<ol class="comment-list">
<?php wp_list_comments(\'callback=custom_comments\');?>
</ol>
<?php endif; ?>
<?php
$comments_args = array(
\'id_form\' => \'commentform\',
\'class_form\' => \'comment-form\',
\'id_submit\' => \'submit\',
\'class_submit\' => \'submit\',
\'name_submit\' => \'submit\',
\'title_reply\' => __( \'Post a comment\' ),
\'title_reply_to\' => __( \'Leave a Reply to %s\' ),
\'cancel_reply_link\' => __( \'Cancel Reply\' ),
\'label_submit\' => __( \'Post Comment\' ),
\'format\' => \'xhtml\',
\'comment_field\' => \'<p class="comment-form-comment"><label for="comment">\' . _x( \'Join the Conversation\', \'noun\' ) .
\'</label><textarea id="comment" placeholder="Comment" name="comment" cols="45" rows="8" aria-required="true">\' .
\'</textarea></p>\',
\'must_log_in\' => \'<p class="must-log-in">\' .
sprintf(
__( \'You must be <a href="%s">logged in</a> to post a comment.\' ),
wp_login_url( apply_filters( \'the_permalink\', get_permalink() ) )
) . \'</p>\',
\'logged_in_as\' => \'<p class="logged-in-as">\' .
sprintf(
__( \' <a href="</a>. <a href="%3$s" title="Log out of this account"></a>\' ),
admin_url( \'profile.php\' ),
$user_identity,
wp_logout_url( apply_filters( \'the_permalink\', get_permalink( ) ) )
) . \'</p>\',
\'comment_notes_before\' => \'<p class="comment-notes">\' .
__( \'\' ) . ( $req ? $required_text : \'\' ) .
\'</p>\',
\'author\' =>
\'<p class="comment-form-author"><label for="author">\' . __( \'Name\', \'domainreference\' ) . \'</label> \' .
( $req ? \'<span class="required">*</span>\' : \'\' ) .
\'<input id="author" name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) .
\'" size="30"\' . $aria_req . \' /></p>\',
\'email\' =>
\'<p class="comment-form-email"><label for="email">\' . __( \'Email\', \'domainreference\' ) . \'</label> \' .
( $req ? \'<span class="required">*</span>\' : \'\' ) .
\'<input id="email" name="email" type="text" value="\' . esc_attr( $commenter[\'comment_author_email\'] ) .
\'" size="30"\' . $aria_req . \' /></p>\',
\'url\' =>
\'<p class="comment-form-url"><label for="url">\' . __( \'Website\', \'domainreference\' ) . \'</label>\' .
\'<input id="url" name="url" type="text" value="\' . esc_attr( $commenter[\'comment_author_url\'] ) .
\'" size="30" /></p>\',
);
comment_form($comments_args);
?>
也有点与问题无关。首先显示评论表单,然后显示姓名、电子邮件和网站表单。有没有办法让名字、电子邮件和网站表单先放在评论表单后放在最后?
最合适的回答,由SO网友:Dave Romsey 整理而成
此代码将允许您自定义注释字段标签,并将注释表单移动到字段下方。将代码添加到functions.php
或插件。
要更改标签,请修改Name CUSTOMIZED
, Email CUSTOMIZED
, 和Website CUSTOMIZED
, 和Comment * CUSTOMIZED
文本
/**
* Customize comment form default fields.
* Move the comment_field below the author, email, and url fields.
*/
function wpse250243_comment_form_default_fields( $fields ) {
$commenter = wp_get_current_commenter();
$user = wp_get_current_user();
$user_identity = $user->exists() ? $user->display_name : \'\';
$req = get_option( \'require_name_email\' );
$aria_req = ( $req ? " aria-required=\'true\'" : \'\' );
$html_req = ( $req ? " required=\'required\'" : \'\' );
$html5 = current_theme_supports( \'html5\', \'comment-form\' ) ? \'html5\' : false;
$fields = [
\'author\' => \'<p class="comment-form-author">\' . \'<label for="author">\' . __( \'Name CUSTOMIZED\', \'textdomain\' ) . ( $req ? \' <span class="required">*</span>\' : \'\' ) . \'</label> \' .
\'<input id="author" name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) . \'" size="30" maxlength="245"\' . $aria_req . $html_req . \' /></p>\',
\'email\' => \'<p class="comment-form-email"><label for="email">\' . __( \'Email CUSTOMIZED\', \'textdomain\' ) . ( $req ? \' <span class="required">*</span>\' : \'\' ) . \'</label> \' .
\'<input id="email" name="email" \' . ( $html5 ? \'type="email"\' : \'type="text"\' ) . \' value="\' . esc_attr( $commenter[\'comment_author_email\'] ) . \'" size="30" maxlength="100" aria-describedby="email-notes"\' . $aria_req . $html_req . \' /></p>\',
\'url\' => \'<p class="comment-form-url"><label for="url">\' . __( \'Website CUSTOMIZED\', \'textdomain\' ) . \'</label> \' .
\'<input id="url" name="url" \' . ( $html5 ? \'type="url"\' : \'type="text"\' ) . \' value="\' . esc_attr( $commenter[\'comment_author_url\'] ) . \'" size="30" maxlength="200" /></p>\',
\'comment_field\' => \'<p class="comment-form-comment"><label for="comment">\' . _x( \'Comment * CUSTOMIZED\', \'noun\', \'textdomain\' ) . \'</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p>\',
];
return $fields;
}
add_filter( \'comment_form_default_fields\', \'wpse250243_comment_form_default_fields\' );
/**
* Remove the original comment field because we\'ve added it to the default fields
* using wpse250243_comment_form_default_fields(). If we don\'t do this, the comment
* field will appear twice.
*/
function wpse250243_comment_form_defaults( $defaults ) {
if ( isset( $defaults[ \'comment_field\' ] ) ) {
$defaults[ \'comment_field\' ] = \'\';
}
return $defaults;
}
add_filter( \'comment_form_defaults\', \'wpse250243_comment_form_defaults\', 10, 1 );