Skip to main content
12 votes
Accepted

How to wrap submit button of comment form with div

We can use comment_form function's submit_button parameter to change submit button HTML. Default HTML for submit_button is <input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" /&...
bravokeyl's user avatar
  • 3,369
5 votes
Accepted

customize comment form

This code will allow you to customize the comment field labels and will move the comment form below the fields. Add the code to your functions.php or to a plugin. To change the labels, modify the ...
Dave Romsey's user avatar
  • 17.7k
5 votes

How to wrap submit button of comment form with div

Please place below code in your theme's functions.php file and it will wrap the submit button inside div: // define the comment_form_submit_button callback function filter_comment_form_submit_button( ...
Prasad Nevase's user avatar
4 votes

Why does comment_reply_link launch the reply form at the wrong spot on the comment section?

Because that's done in javascript, and you have to enqueue that javascript for it to work, as stated in the docs: If JavaScript is enabled and the comment-reply.js JavaScript is loaded the link ...
Tom J Nowell's user avatar
  • 59.6k
3 votes

How to add attributes to the comment form tag?

Use this function rather than comment_form() function validate_comment_form(){ ob_start(); comment_form(); echo str_replace('<form','<form attribute="value" ',ob_get_clean()); }
Farhad Sakhaei's user avatar
3 votes
Accepted

How to add extra input fields to CPT's comment form?

If you have already found the filter inside the comment_form function, you are quite close. There is a filter called comment_form_default_fields which allows you to add extra input fields to the array ...
cjbj's user avatar
  • 14.6k
3 votes

Why does `add_theme_support( 'html5', array( 'comment-form' )` disable client side validation?

No, it is not a bug. This is how core handles it. If you look into /wp-includes/comment-template.php, you'll notice, that the only difference in <form> element, is novalidate attribute added, ...
Frank P. Walentynowicz's user avatar
3 votes
Accepted

Programmatically block commenting by restricting view of comment form

I wonder if you mean this kind of approach: add_filter( 'init', function() { $u = wp_get_current_user(); if( $u->exists() && in_array( 'banned', $u->roles, true ) ) ...
birgire's user avatar
  • 67.4k
3 votes
Accepted

Adding a filter to comments_template

Any comments_template filter should return an absolute filepath to the comments template - use comment_form_defaults and set the class_form argument: add_filter( 'comment_form_defaults', function ( $...
TheDeadMedic's user avatar
  • 36.4k
3 votes

Custom Field Added In Comment Form Not Showing In Edit

Here's all of the code necessary to handle: displaying the custom comment form field on the front end (you already have that) displaying phone number within approved comments editing the phone ...
Dave Romsey's user avatar
  • 17.7k
3 votes
Accepted

WP comments form (custom) is displaying an extra comment field

It seems that WordPress handles the comment field separately than the other fields. If you look at comment_form() in wp-includes/comment-template.php, you can see this. It's possible to set $...
Dave Romsey's user avatar
  • 17.7k
3 votes
Accepted

Remove "at" string from wordpress comment date

Most likely, the 'at' is coming from the value of $comment->comment_date. If that is the case, and since we have to do with string, you could pass it from str_replace first, in order to remove the '...
Cubakos's user avatar
  • 336
2 votes
Accepted

Multiple comment forms on a single page

You can use output buffering to achieve this effect: function get_comments_form() { ob_start(); comments_form(); $commentsform = ob_get_contents(); ob_end_clean(); return $...
majick's user avatar
  • 5,081
2 votes

Custom Field Added In Comment Form Not Showing In Edit

You need to use the add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args ); functionality of WordPress to add the comment extra field to the comments edit. Please have ...
CodeMascot's user avatar
  • 4,527
2 votes

Remove the function which adds nofollow to links in comments

Add this to your plugin file/theme's functions.php: remove_filter( 'pre_comment_content', 'wp_rel_nofollow', 15 ); You could then add your own filter to pre_comment_content to use wp_rel_nofollow ...
Jacob Peattie's user avatar
2 votes
Accepted

WordPress comment submit button substitutes/options

The <a> tag is the wrong tag for a submit button. <input type="submit"> and <button> are designed for this purpose. An <a> tag won't even submit the form data. You need to ...
Jacob Peattie's user avatar
2 votes

How to add consent checkbox in comment section

The 'consent' checkbox is already part of WP Core. See Settings, Discussion, for the "Show comments cookies opt-in checkbox". Enable that, and your comments area will have a GDPR-type checkbox there. ...
Rick Hellewell's user avatar
2 votes

Global $post not working in OOP function WordPress

First function works fine, because comment form is displayed just after post. So it’s the same request and global variable post still contains current post. On the other hand, comment_post is run in ...
Krzysiek Dróżdż's user avatar
2 votes

How to save new comment as custom comment type?

$data = array( 'comment_post_ID' => $post_id, 'comment_author' => 'admin', 'comment_content' => $comment, 'user_id' => $current_user->ID, 'comment_date' => $time, ...
Asha's user avatar
  • 140
2 votes
Accepted

How to make comments private for commentor and post author

You can use the pre_get_comments filter to modify the parameters of the comment query before it fetches the comments. Specifically the author_in parameter. I tried to write an example, though I haven'...
Tom J Nowell's user avatar
  • 59.6k
2 votes

Clicking Comment "Reply" Button only replies to first comment

Your comment replies do not work because you're using a custom comment rendering callback function named better_comments, and this function hardcodes the classes IDs and other attributes rather than ...
Tom J Nowell's user avatar
  • 59.6k
2 votes
Accepted

Wanted to get rid of Paragrapgh tag in submit buttom of the WordPress form

If you control the theme the simplest way to fix this is passing the submit_field argument into comment_form(): comment_form( array( 'submit_field' => '%1$s %2$s', ) ); Default: &...
Rup's user avatar
  • 4,287
1 vote

duplicate comment section functionality and call it something else for custom post types

You can still use the core comment functionality for the custom post type, then filter the edit-comments.php admin screen and create a new admin page with the required comments table. Step 1. ...
Andrii Shekhirev's user avatar
1 vote
Accepted

Conditional/Check: IF comment author is the post author

<?php if ( $post = get_post($post_id) ) : ?> <?php if ( $comment->user_id === $post->post_author ) :?> //do something <?php endif;?> <?php endif;?> Also. <?php ...
Pete's user avatar
  • 1,008
1 vote
Accepted

Custom markup for the comment form

Yeah this should be possible using the comment_form_default_fields filter, like so: apply_filters( 'comment_form_default_fields', $fields ); $fields = array( 'name' => '<section class="form-...
stevenkellow's user avatar
1 vote

comment_for() Custom fields not visible when user is logged in

Ok, so i tried this and it worked as expected, i replaced the above code (used in comment.php) with the one bellow. To correct this issue i simply checked if the user is logged in using ...
Frederick M. Rogers's user avatar
1 vote
Accepted

comment_form() Not changing the default class/id of elements

Those classes are being rendered inline because the id_form, class_form, and class_submit parameters should be placed within the $comments_args array (alongside title_reply, comment_field, etc) and ...
Dave Romsey's user avatar
  • 17.7k
1 vote
Accepted

How can I get values count from wp_commentmeta?

Put the following function in your Theme's functions.php and then put <?php echo tnc_reactions_count($post->ID); ?> in your single.php to output the numbers. Let me know if it works as I have ...
Abdul Awal Uzzal's user avatar
1 vote

How can I test why the comment hook is not working?

To check the values of your variables you can use var_dump or print_r (wrapped in <pre></pre> looks better) you can also enable debug for WordPress and use error_log to write to the debug....
David Lee's user avatar
  • 3,891
1 vote

How can I convert anonymous commenters into registered users?

The register_new_user triggers after the user has been created when the register_new_user() function runs and it will give you the $id of the new user that has been created. If you are using ...
David Lee's user avatar
  • 3,891

Only top scored, non community-wiki answers of a minimum length are eligible