Solution if submit button disappears and notes:
如果您丢失了表单的提交按钮,除了Pieter Goosen的答案之外,您还应该将这些行添加到
defaults
阵列参数列表:
\'submit_button\' => \'<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />\',
\'submit_field\' => \'<p class="form-submit">%1$s %2$s</p>\',
因此,我将用以下内容重写他的完整代码:
function my_comment_form_fields( $args = array(), $post_id = null )
{
if ( null === $post_id )
$post_id = get_the_ID();
else
$id = $post_id;
$commenter = wp_get_current_commenter();
$user = wp_get_current_user();
$user_identity = $user->exists() ? $user->display_name : \'\';
$args = wp_parse_args( $args );
if ( ! isset( $args[\'format\'] ) )
$args[\'format\'] = current_theme_supports( \'html5\', \'comment-form\' ) ? \'html5\' : \'xhtml\';
$req = get_option( \'require_name_email\' );
$aria_req = ( $req ? " aria-required=\'true\'" : \'\' );
$html5 = \'html5\' === $args[\'format\'];
$fields = array(
\'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>\',
);
$required_text = sprintf( \' \' . __( \'Required fiels are marked %s\', \'pietergoosen\' ), \'<span class="required">*</span>\' );
$fields = apply_filters( \'comment_form_default_fields\', $fields );
$defaults = array(
\'fields\' => $fields,
\'comment_field\' => \'<p class="comment-form-comment"><label for="comment">\' . _x( \'Comment\', \'Comments field name\', \'pietergoosen\' ) . \'</label> <textarea id="comment" name="comment" placeholder="\'.__( \'*Required* Enter your comment here. Minimum 20 characters, please\', \'pietergoosen\' ).\'" 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.\', \'pietergoosen\' ), wp_login_url( apply_filters( \'the_permalink\', get_permalink( $post_id ) ) ) ) . \'</p>\',
\'logged_in_as\' => \'<p class="logged-in-as">\' . sprintf( __( \'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>\', \'pietergoosen\' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( \'the_permalink\', get_permalink( $post_id ) ) ) ) . \'</p>\',
\'comment_notes_before\' => \'<p class="comment-notes">\' . __( \'Your email address will not be published.\', \'pietergoosen\' ) . ( $req ? $required_text : \'\' ) . \'</p>\',
\'comment_notes_after\' => \'<p class="form-allowed-tags">\' . sprintf( __( \'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s\', \'pietergoosen\' ), \' <code>\' . allowed_tags() . \'</code>\' ) . \'</p>\',
\'id_form\' => \'commentform\',
\'id_submit\' => \'submit\',
\'title_reply\' => __( \'Leave a Reply\', \'pietergoosen\' ),
\'title_reply_to\' => __( \'Leave a Reply to %s\', \'pietergoosen\' ),
\'cancel_reply_link\' => __( \'Cancel reply\', \'pietergoosen\' ),
\'label_submit\' => __( \'Post Comment\', \'pietergoosen\' ),
\'format\' => \'xhtml\',
\'submit_button\' => \'<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />\',
\'submit_field\' => \'<p class="form-submit">%1$s %2$s</p>\',
);
return $defaults;
}
add_filter(\'comment_form_defaults\', \'my_comment_form_fields\');
Important notes:
请记住,关键字“pietergoosen”是您在主题的“style.css”中找到的“文本域”或主题名称。对我来说,先把任何东西放在随机的位置都是可行的,但最好用正确的方法。
2-您不必修改主主题的functions.php
让这一切顺利进行。这将导致您的工作在更新后消失。创建新的child theme. 创建子主题后,您所要做的就是创建一个名为functions.php
, 从<?php
, 然后写下表单的代码。请勿结束functions.php
以通用PHP代码结尾?>
. 这就是wordpress的语法functions.php
.
干杯