Jetpack là một plugin wordpress phổ biến và rất nhiều người dùng wordpress đang sử dụng plugin này. Plugin này có một mô-đun “ Đăng ký Jetpack ” và mô-đun này đang thêm hai hộp kiểm vào biểu mẫu nhận xét. Jetpack không cung cấp bất kỳ cài đặt bổ sung nào để định vị lại hai hộp kiểm này. Sử dụng CSS, chúng tôi có thể di chuyển nút “Đăng nhận xét” bên dưới các hộp kiểm. Nhưng là một lập trình viên PHP, làm thế nào bạn có thể làm điều này bằng tập lệnh PHP? Bài viết này sẽ cung cấp mã.
Đầu tiên Xóa các hộp kiểm
Theo bộ lọc
add_filter('jetpack_comment_subscription_form', 'gd_jp_comment_subscription_form'); function gd_jp_comment_subscription_form($str){ return ''; }
HOẶC
Bởi Hook
add_action( 'get_header', 'gd_remove_jp_subscriptions_boxes' ); function gd_remove_jp_subscriptions_boxes() { if (class_exists('Jetpack_Subscriptions')) remove_action( 'comment_form', array( Jetpack_Subscriptions::init(), 'comment_subscribe_init' ) ); }
Thứ hai, thêm hai hộp kiểm phía trên nút Gửi
Thêm mã sau vào tệp functions.php
//* Remove comment form allowed tags add_filter( 'comment_form_defaults', 'gd_remove_comment_form_allowed_tags' ); function gd_remove_comment_form_allowed_tags( $defaults ) { global $post; $defaults['comment_notes_after'] = ''; if (class_exists('Jetpack_Subscriptions')) { $str = ''; $comments_checked = ''; $blog_checked = ''; if ( FALSE === has_filter( 'comment_form', 'show_subscription_checkbox' ) && 1 == get_option( 'stc_enabled', 1 ) && empty( $post->post_password ) ) { // Subscribe to comments checkbox $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_comments" id="subscribe_comments" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $comments_checked . ' /> '; $str .= '<label class="subscribe-label" id="subscribe-label" for="subscribe_comments">' . __( 'Notify me of follow-up comments by email.', 'jetpack' ) . '</label>'; $str .= '</p>'; } if ( 1 == get_option( 'stb_enabled', 1 ) ) { // Subscribe to blog checkbox $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_blog" id="subscribe_blog" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $blog_checked . ' /> '; $str .= '<label class="subscribe-label" id="subscribe-blog-label" for="subscribe_blog">' . __( 'Notify me of new posts by email.', 'jetpack' ) . '</label>'; $str .= '</p>'; } $defaults['submit_field'] = $str . $defaults['submit_field'] ; } return $defaults; }
Bây giờ hãy làm mới trang chi tiết bài đăng duy nhất của bạn và bạn sẽ nhận được điều này.