個人サイトではさほど需要はないけれど、企業サイトではちょくちょくコメント関係の変更を言われますので、とりあえず、コメントフォームのカスタマイズについてです。
comments.phpいじることになります。
ちなみに、コメントフォームの引数はデフォルトでこうなってます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php $defaults = array( 'fields' => apply_filters( 'comment_form_default_fields', $fields ), 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="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( $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>' ), admin_url( 'profile.php' ), $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.' ) . ( $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' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>', 'id_form' => 'commentform', 'id_submit' => 'submit', 'title_reply' => __( 'Leave a Reply' ), 'title_reply_to' => __( 'Leave a Reply to %s' ), 'cancel_reply_link' => __( 'Cancel reply' ), 'label_submit' => __( 'Post Comment' ), ); ?> |
- fields: 名前、メールアドレス、URL部分(この部分の変更は後ほど)
- comment_field:コメント本文の部分
- must_log_in:ユーザー登録必須の際に、ユーザー登録を促すリンクを表示
- logged_in_as:ユーザー登録済みでログイン中の場合に表示(ユーザー編集画面へのリンクなど)
- comment_notes_before:コメントフォームの注意書きなど(メールアドレスは非公開とか)
- comment_notes_after:comment_fieldの後に表示する部分(次のHTMLとタグが使えますのとこ)
- id_form:コメントフォームのID属性値
- id_submit:コメントフォームのsubmitボタンのID属性値
- title_reply:フォームの見出し「コメントを残す」
- title_reply_to:返信の時の見出し「コメントを残す」
- cancel_reply_link:返信の時の取り消しリンク「コメントをキャンセル」
- label_submit submit:ボタンに表示される文字「コメントを送信」
需要が多いのは、下4つと、コメント前「メールアドレスが公開されることはありません。 * が付いている欄は必須項目です」とコメント後「次のHTML タグと属性が使えます・・・」の変更。
なので、ここだけ変更するパターンで。
1 2 3 4 5 6 7 8 9 10 |
<?php comment_form(array( 'comment_notes_before'=>'<p class="comment-notes">' . __( 'アドレスは任意です。お気軽にコメント下さい。' ) . ( $req ? $required_text : '' ) . '</p>', 'comment_notes_after' => ''; /*「次のhtml タグと属性が使えます」を消す*/ 'title_reply' => __( 'コメントよろしく' ), 'title_reply_to' => __( 'へんしーん' ), 'cancel_reply_link' => __( '間違えた、もう一回' ), 'label_submit' => __( '送信しまーす' ), )); ?> |
必要なところを変更して、commemts.php内の <?php comment_form(); ?;> のところを書き換えればOKです。日本語で打ち込んでかまいません。
3行目で、コメント後のメッセージ「次のHTML タグと属性が使えます・・・」を削除して非表示にしていますが、単に表示させたくないというときは、cssで
1 |
.form-allowed-tags{display: none;} |
という風に該当classを、非表示にするのもありです。子テーマ使うとかしてね
- 投稿タグ
- カスタム