I'm currently working with custom comment meta, and I have some custom additional field such as rating etc, when user write a comment ( not comment reply ) I want to show the rating field, but when it's on reply comment state I want to remove this field.

Is there a build in conditional function to check whether it's in a reply state or not? or any other way to achieve what I want?


Check for the comment_parent:

if( '0' != $comment->comment_parent ){
    // this is a reply
  • thanks for the answer @diggy, I'm using comment_form() function to output the comment in the theme, so how can I do this using comment hook? – nonsensecreativity Jan 16 '13 at 0:21
  • comment_form displays the form, I assume you want to customize comments, and not the form? Check for wp_list_comments to find out what callback function is used to display comments, e.g. in twentytwelve the callback is twentytwelve_comment, which is located in functions.php. Edit the callback function to incorporate the rating data, e.g. <?php if ( '0' == $comment->comment_parent ) : ?>RATING STUFF GOES HERE<?php endif; ?> – diggy Jan 16 '13 at 0:30
  • I just made it work using global $comment in the comment_form_after_fields action, one thing not going well is when I open the link to reply manually it work eq.(localhost/wp/?p=123&replytocom=17#respond) , but not while using comment-reply.js when the comment is just move to another place but not removing the field. Any idea? – nonsensecreativity Jan 16 '13 at 0:36

I realize this question is quite old, but I just solved this problem today with a JQuery-based approach.

jQuery( function() {
  jQuery("#commentform").attr("data-parsly-validate", " ");


  jQuery(".comment-meta-header .comment-reply-link").click(function(){
    jQuery("#commentform .comment-form-area, #commentform .comment-form-type").hide();
    jQuery("#starling-comment-area, #starling-comment-type").removeAttr("required");

    jQuery("#commentform .comment-form-area, #commentform .comment-form-type").show();
    jQuery("#starling-comment-area, #starling-comment-type").attr("required", " ");

Basically I have click handlers for when the "Reply" or "Cancel" links are clicked, and I handle form validation with Javascript (using Parsley, in this case).

For server-side validation you can use diggy's solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.