I have simple fuction that adds additional comment form field called “Subject”:
add_action( 'comment_form_logged_in_before', 'additional_fields' );
add_action( 'comment_form_before_fields', 'additional_fields' );
function additional_fields () {
echo '<p class="comment-form-subject">'.
'<label for="subject">' . __( 'Your subject' ) . '</label>'.
'<input id="subject" name="subject" type="text" size="30" tabindex="5" /></p>';
}
It works fine, but just now it adds “Subject” field to every comment form.
I need to add this field only for first level/depth of comments.
My goal is:
When user will reply directly to post, he will get “Subject” field in reply form.
When user will reply to comment, he will not see “Subject” field in reply form.
The Reply links
I assume your Reply links look like this:
and the Cancel Reply link:
The Javascript method
addComment.moveForm
is defined in/wp-includes/js/comment-reply.min.js
.Demo plugin:
To hide the extra Subject field for comments replies, you can try to check for the
replytocom
GET parameter for the non-Javascript case and hook into the click event for the Javascript case.Here is a demo Comment Subject plugin:
/wp-content/plugins/comment-subject/comment-subject.php
:where you add the file
/wp-content/plugins/comment-subject/js/script.js
containing:Let me throw a simple CSS-only solution into the hat:
This solution assumes you are using
comment_class
.How about using a conditional to check if there are comments? If not, display a different comment form.
Use this snippet inside your single.php, paste it in while loop before comments open function, this will get you solution.