0

I would like to put a prewritten comment in the WordPress comment section by modifying comments.php:

<?php if ( comments_open() ) { comment_form(array(
'title_reply'=>'',
'label_submit' => esc_html__( 'Send!' ),
'comment_field' => esc_html__( 'Prewritten comment' ),
)); } ?>

The two first adjustments above works fine. What should the third one be to fullfil my wish?

PS. I found the snippet below in a similar functions.php filter that might be of help to someone more capable than me?

$fields['comment_field'] = str_replace(
        '</textarea>',
        'EXTRA CONTENT</textarea>',
        $fields['comment_field']
2
  • rather than doing this which means as a commenter I have to delete the contents, would it not be more accessible and user friendly to use a placeholder="prewritten text" attribute instead? What problem are you trying to solve with this?
    – Tom J Nowell
    Commented May 19, 2023 at 15:51
  • I'm building a site where the comment section is used for booking stuff (i.e. posts). So I actually don't want the commenter to submit anything else that the prewritten comment. In the end I even added style="display:none" to the textarea-tag so that the commenter can't see/edit/delete the comment, but just hit a button :)
    – joxyzan
    Commented May 20, 2023 at 12:16

1 Answer 1

1

I was answered in the Wordpress Forums. The solution is to pass the entire HTML for the comment_field, like this:

'comment_field' => '<textarea id="comment" name="comment" cols="45" rows="5" maxlength="65525" required="">'. __('Prewritten comment','textdomain').'</textarea>',
2
  • where is this file where you changed that?
    – razvanli
    Commented Aug 13, 2023 at 10:02
  • @razvanli the OP mentioned it, comments.php, but this may not exist in your theme, or may be in a different file, nobody can tell you for sure unless you gave them your entire site
    – Tom J Nowell
    Commented Aug 13, 2023 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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