admin管理员组文章数量:1426855
I want to change the titles "Name", "Email", and "Website" in my comment form?. How could I do this? I thought by changing them in this field would work ( 'Website', 'domainreference' ) but it doesn't change anything. Any help would be appreciated.
Here is my comments.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);
?>
Also kind of unrelated to the question. The comment form shows up first and is then followed by the Name, Email, and Website forms. Is there a way to make it so that the Name, Email, and Website forms are first followed by the comment form last?
I want to change the titles "Name", "Email", and "Website" in my comment form?. How could I do this? I thought by changing them in this field would work ( 'Website', 'domainreference' ) but it doesn't change anything. Any help would be appreciated.
Here is my comments.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);
?>
Also kind of unrelated to the question. The comment form shows up first and is then followed by the Name, Email, and Website forms. Is there a way to make it so that the Name, Email, and Website forms are first followed by the comment form last?
Share Improve this question edited Dec 23, 2016 at 21:37 user6738171 asked Dec 23, 2016 at 21:30 user6738171user6738171 1771 gold badge6 silver badges15 bronze badges1 Answer
Reset to default 5This code will allow you to customize the comment field labels and will move the comment form below the fields. Add the code to your functions.php
or to a plugin.
To change the labels, modify the Name CUSTOMIZED
, Email CUSTOMIZED
, and Website CUSTOMIZED
, and Comment * CUSTOMIZED
text.
/**
* 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 );
本文标签: htmlcustomize comment form
版权声明:本文标题:html - customize comment form 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745482540a2660241.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论