• Daniel

    (@wrecclesham)


    I’ve modified my contact form using comments.php to remove the “Name” and “Email” field labels from inside those fields but am struggling to do the same thing for the “Comment” field. I can’t simply delete the necessary text from the PHP file, as I was able to do with the other two fields.

    I’ve tried following the instructions here:

    https://codex.www.ads-software.com/Function_Reference/comment_form#Default_.24args_array

    Here is the corresponding section in my comments.php file:

    comment_form( array( ‘fields’ => $fields, ‘label_submit’ => esc_attr__( ‘Submit’, ‘Divi’ ), ‘title_reply’ => ‘<span>’ . esc_attr__( ‘Leave a comment’, ‘Divi’ ) . ‘</span>’, ‘title_reply_to’ => esc_attr__( ‘Leave a Reply to %s’, ‘Divi’ ), ‘class_submit’ => ‘submit et_pb_button’, comment_notes_before
    =>'<p class=”comment-notes”>’ . __( ” ) . ‘</p>’ ) ); ?>

    Can someone please tell me what I need to do to this code in order to prevent my contact form’s “Comment” field from automatically populating with the word “Comment”? Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • lisa

    (@contentiskey)

    looks like Divi builder is active on the site.
    contact Divi builder support to get help to change details displayed in comment area
    https://www.elegantthemes.com/plugins/divi-builder/

    Thread Starter Daniel

    (@wrecclesham)

    Hi Lisa,

    So I actually asked Elegant Themes support for help with this issue yesterday but they weren’t very helpful.

    “Thanks for letting me know. I am afraid we do not offer customization or full website services, sorry about that. You could try a freelancer site such as https://www.Upwork.com.

    Also, that form is not the Comments Module of Divi and it is the default comment from WordPress. You may try checking this helpful guide that seems to be related to your case. https://crunchify.com/wordpress-comment-form-customization/

    Hope that helps!”

    The guy initially suggested I use some jQuery to “hide” it but the word “Comment” still appeared for a second, and then disappeared afterwards, when his script kicked in. I said that clearly wasn’t an elegant solution and I simply wanted to delete it outright, instead of “hiding” it, at which point he said he couldn’t help/it was outside his scope of support.

    I’m a bit confused because they were able to help me to remove the default label from the other two fields in my contact form but not this one.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    
    add_filter( 'comment_form_defaults', 'kill_comment_label' );
    function kill_comment_label( $defaults ) {
    	$defaults['comment_field'] = '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p>',
    	return $defaults;
    }
    

    That code will let you edit the default comment field. It is unchanged as is, just copied from the original. To edit it, just remove the label and such, as you like.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Alternatively, in your existing comment_form call, pass in a new ‘comment_field’ with your content. That will override the default field value.

    Thread Starter Daniel

    (@wrecclesham)

    Hi Samuel,

    I tried pasting that into the end of my comments.php file and then tinkering with it, but I’m still not 100% sure what I need to do.

    As a test, when I changed “Comment” to “Comment1”, my site still showed “Comment”, so it feels like I’m doing something wrong already.

    Any ideas?

    Here’s what the end of my comments.php file looks like (this is just an excerpt to give you some context):

    comment_form( array( ‘fields’ => $fields, ‘label_submit’ => esc_attr__( ‘Submit’, ‘Divi’ ), ‘title_reply’ => ‘<span>’ . esc_attr__( ‘Leave a comment’, ‘Divi’ ) . ‘</span>’, ‘title_reply_to’ => esc_attr__( ‘Leave a Reply to %s’, ‘Divi’ ), ‘class_submit’ => ‘submit et_pb_button’, comment_notes_before
    =>'<p class=”comment-notes”>’ . __( ” ) . ‘</p>’ ) ); ?>
    <?php else: ?>

    add_filter( ‘comment_form_defaults’, ‘kill_comment_label’ );
    function kill_comment_label( $defaults ) {
    $defaults[‘comment_field’] = ‘<p class=”comment-form-comment”><label for=”comment”>’ . _x( ‘Comment1’, ‘noun’ ) . ‘</label> <textarea id=”comment” name=”comment” cols=”45″ rows=”8″ maxlength=”65525″ required=”required”></textarea></p>’,
    return $defaults;
    }
    <?php endif; // if you delete this the sky will fall on your head ?>
    </section>

    • This reply was modified 5 years, 9 months ago by Daniel.
    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    It won’t work there. It’s a filter, so you need to have it before you call the comment_form function. Also, you have the code outside of a PHP block. That won’t work either.

    Try just adding 'comment_field' => '<p class="comment-form-comment"><textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p>' to the end of the arguments list you already have in the comment_form function call instead.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to delete “Comment” default text from inside the Comment field?’ is closed to new replies.