おかぴーです。
記事のコメント欄にちょっとした文言を追加したい場合のカスタマイズ方法を今回はご紹介しようと思います。
例えば、僕のコメント欄の場合は↓2つのファイルを使って対応しています。
- THE THORのテーマ内のPHPファイル
- WordPressのテンプレートファイル
②のファイルは、どのWordPressテーマを使っていても共通のファイルになるので、カスタマイズの参考になると思いますよ。


では、さっそく本題へ↓
「wp-content > themes > the thor > comments.php」
↑にあるcomments.phpファイルを使います。
ただし、親テーマではなく、必ず子テーマに複製してから、
「wp-content > themes > the thor child > comments.php」
のファイルを編集しましょう。
<親テーマの場所(右上がTHE THOR)>
<子テーマの場所(右上がTHE THOR CHILD)>
- FTPソフトを利用して子テーマに複製します。やり方を知りたい方はこちら↓
-
関連記事
おかぴー こんにちは、WEBデザイナーのおかぴーです! 絵を描く仕事をしたかった僕が、WEBデザイナーを選んだプロフィールはこちらへ。 稼げるブログを作りたい人はこちらへ。 WordPressで子テー[…]
'title_reply' => 'コメントを書く',
'label_submit' => __( 'コメントを送信' , 'default' ),
'title_reply_before' => '<h2 class="heading heading-secondary">',
'title_reply_after' => '</h2>',
);
comment_form( $args ); ?>
'title_reply' => 'コメントもらえると嬉しいです(o^^o)',
'label_submit' => __( 'コメントを送信' , 'default' ),
'title_reply_before' => '<h2 class="heading heading-secondary">',
'title_reply_after' => '</h2>',
);
comment_form( $args ); ?>
WordPressのテンプレートファイル
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $html_req . ' /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $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"' . $html_req . ' /></p>',
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
'<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>',
);
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $html_req . ' /></p>',

- 'author':「名前」欄
- 'email':「メール」欄
- 'url':「サイト」欄
例えば、↓のようなコメント欄を作る場合は、
'<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"' . $html_req . ' /></p>',
'<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"' . $html_req . ' /></p>',
'<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>',
→url欄は、「 '' 」シングルクォーテーションを残して、中身を削除すると表示されなくなります。
いかがでしたでしょうか。
コメント欄の使い方次第では、あなたのファンが増えるきっかけを作ることができるので、
ぜひあなただけのコメント欄を作って、読者の方とのコミュニケーションを楽しんでみてくださいね(*^^*)