Jetpack is a popular wordpress plugin and lot of wordpress users are using this plugin. This plugin have a module “Jetpack Subscription” and this module is adding two checkboxes into comment form. Jetpack is not providing any extra settings for repositioning this two checkboxes. Using CSS we can move the “Post Comment” button below the checkboxes. But as a PHP programmer how you can do this by PHP script? This article will provide the code.
First Removing the checkboxes
By Filter
1 2 3 4 |
add_filter('jetpack_comment_subscription_form', 'gd_jp_comment_subscription_form'); function gd_jp_comment_subscription_form($str){ return ''; } |
OR
By Hook
1 2 3 4 5 |
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' ) ); } |
Second adding the two checkboxes above the Submit button
Add the following code in functions.php file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
//* 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; } |
Now refresh your single post details page and you’ll get this. See the screenshot.
Niranjan says
I always your short and clear tutorial. But I need little more help.
How to auto check both checkboxes?
Nemanja says
Hi,
I know it’s an old post but I find it quite useful.
I have an issue that’s probably related to my theme, but maybe you can help. Your code worked perfectly to put checkboxes above the button, but the text moves to a new line. So I have a checkbox and the text that follows it is in a new line and not next to the checkbox.
Can you please help?
Paul says
Can you share the site URL?
I’m guessing that this CSS can work
Nemanja says
Hi,
It didn’t change anything. I’ve put the CSS in theme’s style.css file? I had this problem before applying your code, so I guess it’s something with the theme.
http://www.lazarica-ljubic.rs
Syed Hamza says
How can I auto check the “NOTIFY ME OF FOLLOW-UP COMMENTS BY EMAIL”?
Imre says
Thank you very much! My Theme wasn’t showing for whatever reasons the “subscribe to upcoming posts” part (the the other one), but your script does it show. This really helped me a lot! Thanks
Evah says
Hello, and thank you for this tutorial.
I would like to put the checkboxes under the last field (url) of my form, and I have change the $fields in my comments.php, can you explain how to do this ?
Thank !
Paul says
Are you added the above code? If you follow my steps and add the code in your functions.php file then it will add the checkboxes above the submit button.
Evah says
Hello and thanks for your answer.
If I add your code to the functions.php, the checkbox go under the textarea, and not between the last field (url) and the submit button, as you can see in the picture :
http://espace.sythin.net/wp-content/uploads/checkboxes.png
I have tried to change the line 26 ($defaults[‘comment_field’] = $defaults[‘comment_field’] . $str;) but I haven’t find what to write instead.
Paul says
Replace this line ($defaults[‘comment_field’] = $defaults[‘comment_field’] . $str;) With following code:
[code]
if( is_user_logged_in() )
$defaults[‘comment_field’] = $defaults[‘comment_field’] . $str;
else
$defaults[‘url’] = $defaults[‘url’] . $str;
]
Evah says
The “if” is working, but the “else” isn’t 🙁
Paul says
Completely remove this
[code]
if( is_user_logged_in() )
$defaults[‘comment_field’] = $defaults[‘comment_field’] . $str;
else
$defaults[‘url’] = $defaults[‘url’] . $str;
]
And add this line
[code]$defaults[‘submit_field’] = $str . $defaults[‘submit_field’] ;]
Hope it will work.
Evah says
It’s perfect !
Thank you very much !
Paul says
Glad to help you.
Vic says
How can I auto check the notify me of new posts box?
Paul says
Add this line:
[code]$blog_checked = $comments_checked = ‘checked’;]
Below this line :
[code]$str= ”;]
Niranjan says
I use genesis framework. I added $blog_checked = $comments_checked = ‘checked’; below $str= ”; in functions.php on childtheme. It is not working. Any other suggestion?
Niranjan says
Yeah.. I removed $comments_checked = ”;
$blog_checked = ”;. Now it is working.
Paul says
This didn’t work for me.
It would remove the checkboxes fine, but would not add them back in.
I ended up using a little bit of CSS instead.
Thought I’d leave it here, in case someone else has the same problem.
.commentsBox .comment-form p.form-submit {
position: relative;
top: 120px;
}
.commentsBox .comment-form .comment-subscription-form {
position:relative;
top: -80px;
}
Paul says
Hi Paul
My PHP Code is 100% working perfectly. I added the code in my functions.php file. For live preview check my comment form. Two checkboxes are coming above the submit button now.
I am sure that you did something wrong at your end. For that reason it was not working at your end.
Best
Chinmoy