Genesis Framework cho phép bạn tùy chỉnh bất kỳ phần nào của chủ đề con và làm cho nó trở thành của riêng bạn. Một trong những thủ thuật tùy biến Genesis dễ dàng đó là tuỳ chỉnh phần comment trong Genesis và làm cho nó trở thành của riêng bạn.
Nếu bạn là người hay dùng khung comment Genesis, bạn sẽ biết Genesis có một vài đoạn mã mà trong đó bạn có thể sử dụng ở file functions.php của chủ đề con để thay đổi nút gửi bình luận, ghi chú và giao diện của các phần khác nhau trong nhận xét. Với một chút thay đổi CSS, phần comment của bạn trông sẽ rất khác với bản gốc.
Trong các chủ đề con của Genesis, phần nhận xét thường có hai phần ‘Gửi comment mới‘ và ‘Trả lời‘.
Dựa trên yêu cầu của bạn, bạn có thể muốn sử dụng một trong các đoạn tùy chỉnh phần ý kiến trong child theme Genesis của bạn.
Hướng dẫn tùy chỉnh khung Comment toàn tập trong theme genesis
Chúng ta xem những gì có thể thay đổi trong phần comment này nào?
Sửa đổi phần tiêu đề nhận xét
//* Thay đổi tiêu đề comments add_filter( 'genesis_title_comments', 'topleague_genesis_title_comments' ); function topleague_genesis_title_comments() { $title = '<h3>Bình luận</h3>'; return $title; }
Sửa đổi kích thước Gravatar trong bình luận Genesis
//* Thay đổi kích thước Gravatar trong comments add_filter( 'genesis_comment_list_args', 'topleague_comments_gravatar' ); function topleague_comments_gravatar( $args ) { $args['avatar_size'] = 96; // change the number depending on your requirement return $args; }
Sửa đổi chữ tác giả nói trong Genesis
//* Thay đổi chữ tác giả nói trong comments add_filter( 'comment_author_says_text', 'topleague_comment_author_says_text' ); function topleague_comment_author_says_text() { return 'Đã nói'; }
Xóa link thời gian viết nhận xét
// Xóa link thời gian viết nhận xét trong comment add_filter( 'genesis_show_comment_date', 'topleague_remove_comment_time_and_link' ); function topleague_remove_comment_time_and_link( $comment_date ) { printf( '<p %s>', genesis_attr( 'comment-meta' ) ); printf( '<time %s>', genesis_attr( 'comment-time' ) ); echo esc_html( get_comment_date() ); echo '</time></p>'; return false; }
Thay đổi dòng chữ Leave a Reply
//* Thay đổi chữ 'Leave a Reply' trong comments add_filter( 'comment_form_defaults', 'topleague_comment_form_defaults' ); function topleague_comment_form_defaults( $defaults ) { $defaults['title_reply'] = __( 'Trả lời' ); return $defaults; }
Thêm chính sách trong genesis
//* Thêm chính sách bảo mật trong comments add_action( 'genesis_after_comments', 'topleague_comment_policy' ); function topleague_comment_policy() { if ( is_single() && !is_user_logged_in() && comments_open() ) { ?> <div class="comment-policy-box"> <p class="comment-policy"><small><strong>Chính sách comment:</strong> Không spam link trong bài viết.</small></p> </div> <?php } }
Lưu ý: Bạn có thể muốn thêm một css nhỏ để làm nổi bật hộp chính sách nhận xét. Ví dụ:
.comment-policy-box { background: #fff; Padding: 0 15px; }
Xóa thẻ được phép trong Genesis
//* Xóa thẻ được cho phép comment add_filter( 'comment_form_defaults', 'topleague_remove_comment_form_allowed_tags' ); function topleague_remove_comment_form_allowed_tags( $defaults ) { $defaults['comment_notes_after'] = ''; return $defaults; }
Sửa đổi nút Submit trong Genesis
//* Thay đổi chữ submit trong comments add_filter( 'comment_form_defaults', 'topleague_comment_submit_button' ); function topleague_comment_submit_button( $defaults ) { $defaults['label_submit'] = __( 'Gửi bình luận'); return $defaults; }
Thêm hoặc xóa ghi chú sau hộp chú thích trong Genesis
// Thêm hoạc xáo ghi chú sau hộp chú thích trong comment add_filter( 'comment_form_defaults', 'topleague_remove_comment_form_allowed_tags' ); function topleague_remove_comment_form_allowed_tags( $defaults ) { $defaults['comment_notes_after'] = 'Enter the Following Details'; return $defaults; }
Chỉnh sửa Trackbacks Văn bản tiêu đề trong Genesis
//* Chỉnh sửa chữ trackbacks trong comments add_filter( ‘genesis_title_pings’, ‘topleague_title_pings’ ); function topleague_title_pings() { echo ‘<h3>Trackbacks</h3>’; }
Xem thêm các bài viết về hướng dẫn sử dụng wordpress trên website để tùy biến các chức năng khác trong comment nhé!
Chúc bạn thành công