Luxeritasのコメント欄を変更

とっても素敵なWPテーマ「Luxeritas

いろんなWPテーマを比較して、一番気に入ったので利用させて頂いているけど、コメント欄がイマイチ気に入らない・・・

主に直したい内容は以下!

  • メールアドレス欄不要
  • ウェブサイト欄不要
  • 名前入力は任意
  • [次回のコメントで使用するためブラウザーに自分の名前、メールアドレス、サイトを保存する。] を削除
  • 入力順を「名前」→「コメント」の順番にしたい
  • スパム対策をしたい
  • デザインの微調整したい

 

<注意>

以降、記事内に出てくる「functions.php」は、

必ず子テーマフォルダの [wp-content/themes/luxech/functions.php] を修正をする事

 

メール・ウェブ欄削除/名前任意

「メールアドレス欄」「ウェブサイト欄」「名前入力任意」までは公式サイトにやり方が掲載されています。

公式サイト様と他サイト様のやり方を見ながら、対応していけばさくっと出来ちゃいます。

 

必須を解除

本体設定で「必須」扱いになっている設定を解除

おそらく、この設定を忘れるとコメント入力の時にPHPエラー出るんじゃないかなぁ

「設定 -> ディスカッション」

 

メール・ウェブ欄削除

functions.phpに以下のソースコードを貼り付け

// 「メールアドレス」「ウェブサイト」を消す
add_filter( 'comment_form_default_fields', function( $fields ) {
  unset( $fields['url'], $fields['email'] );
  return $fields;
}, 8 );

参照:https://thk.kanzae.net/net/wordpress/t9269/

 

「メールアドレスが公開されることはありません。」の注記を削除

functions.phpに以下のソースコードを貼り付け

// 「メールアドレスが公開されることはありません。」を消す
add_filter( "comment_form_defaults", "my_comment_notes_before");
function my_comment_notes_before( $defaults){
 $defaults['comment_notes_before'] = '';
 return $defaults;
}

参照:http://kwski.net/wordpress/1060/

 

[次回のコメントで使用するためブラウザーに自分の名前、メールアドレス、サイトを保存する。] を削除

本体設定でCookie保存する設定を解除

「設定 -> ディスカッション」

参照:https://techmemo.biz/wordpress/comment-cookie-check-disable/

 

入力順を「名前」→「コメント」の順番にしたい

functions.phpに以下のソースコードを貼り付け

// 入力項目の順番を入れ替える
add_filter( 'comment_form_fields', 'move_comment_field_to_bottom' );
function move_comment_field_to_bottom( $fields ) {
 $comment_field = $fields['comment'];
 unset( $fields['comment'] );
 $fields['comment'] = $comment_field;
 return $fields;
}

 

スパム対策をしたい

『Invisible reCaptcha』というプラグインを導入しました

参照:https://www.vektor-inc.co.jp/post/invisible-recaptcha-for-wordpress/

 

デザインの微調整したい

[wp-content/themes/luxech/style.css]に以下のCSSを追加

#comments textarea{
 height: 100px !important;
}
#commentform{
 flex-direction: column;
}
#commentform .form-submit{
 margin-bottom: 20px;
}
#comments [type=submit]{
 background: #dc143c;
 transition: opacity .3s;
}
#comments [type=submit]:hover{
 opacity: 0.6;
}

 

結果

  • メールアドレス欄不要 (済)
  • ウェブサイト欄不要(済)
  • 名前入力は任意(済)
  • [次回のコメントで使用するためブラウザーに自分の名前、メールアドレス、サイトを保存する。] を削除(済)
  • 入力順を「名前」→「コメント」の順番にしたい(済)
  • スパム対策をしたい(済)
  • デザインの微調整したい(済)

うん、だいぶスッキリしました!

 

設定まとめ

WordPress設定

「設定 -> ディスカッション」

  • 「コメントの投稿者の名前とメールアドレスの入力を必須にする」を解除
  • 「コメント投稿者が Cookie を保存できるようにする。 Cookie オプトイン用チェックボックスを表示します」を解除

 

functions.php

[wp-content/themes/luxech/functions.php]

<?php
/**
* Luxeritas WordPress Theme - free/libre wordpress platform
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* @copyright Copyright (C) 2015 Thought is free.
* @link http://thk.kanzae.net/
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
* @author LunaNuko
*/

/* 以下、好みに応じて子テーマ用の関数をお書きください。
( Below here, please write down your own functions for the child theme. ) */

//「メールアドレス」「ウェブサイト」を消す
add_filter( 'comment_form_default_fields', function( $fields ) {
 unset( $fields['url'], $fields['email'] );
 return $fields;
}, 8 );

// 「メールアドレスが公開されることはありません。」を消す 
add_filter( "comment_form_defaults", "my_comment_notes_before");
function my_comment_notes_before( $defaults){
 $defaults['comment_notes_before'] = '';
 return $defaults;
}

// 入力項目の順番を入れ替える
add_filter( 'comment_form_fields', 'move_comment_field_to_bottom' );
function move_comment_field_to_bottom( $fields ) {
 $comment_field = $fields['comment'];
 unset( $fields['comment'] );
 $fields['comment'] = $comment_field;

 return $fields;
}

 

style.css

[wp-content/themes/luxech/style.css]

#comments textarea{
  height: 100px !important;
}
#commentform{
  flex-direction: column;
}
#commentform .form-submit{
  margin-bottom: 20px;
}
#comments [type=submit]{
  background: #dc143c;
  transition: opacity .3s;
}
#comments [type=submit]:hover{
  opacity: 0.6;
}

CSS, PHP, Wordpress

Posted by takahiro