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,349
8 votes

How to rearrange fields in comment_form()

There are obviously a number of ways to accomplish this. For example, to move the comment field to the bottom of the form you would use code like this: add_filter( 'comment_form_fields', '...
Josh C's user avatar
  • 273
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
5 votes
Accepted

Comment form not showing up without comments

Ok I feel stupid now. The problem was that for whatever reason some of the posts had comments disabled. I did not know that the only place where they could be toggled was under "Quick Edit". Problem ...
fnx's user avatar
  • 181
5 votes

Comment form not display properly?

Comment.php The way I see your comment.php seems messy and more complex than it needs to be, you can post this piece of code to in your comment.php and it should work okay. <?php /** * If the ...
Stephen's user avatar
  • 1,294
4 votes

Comment Walker vs. Comment Callback

We could rewrite: wp_list_comments( array( 'callback' => 'bootstrap_comment_callback', )); with the null walker parameter: wp_list_comments( array( 'walker' => null, ...
birgire's user avatar
  • 67.1k
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.2k
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

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
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

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

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.1k
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.5k
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

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

Comment Walker vs. Comment Callback

In the simplest of explanations, the callback argument for wp_list_comments() is used to reference a function that will build the beginning of an individual comment. (The end-callback argument ...
darrinb's user avatar
  • 1,226
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

How can comments be submitted when I don't have a comment box on a page?

The visual representation of a comment form (or lack of it) do not have any impact on the ability to receive comments, and spammers usually don't care at all what is in your form. Wordpress have a ...
Mark Kaplun's user avatar
  • 23.4k
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.2k
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.2k
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,247
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
  • 998
1 vote

display user roles in comment form

This will print User Role global $current_user; $user_role = $current_user->roles[0]; echo $user_role; Use above code, where ever you want to display user role.
Rishabh's user avatar
  • 974

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