Remove Required Comment Textarea (Repost)
-
You can achieve it with the help of comment_form() codex.
(1) To make the comment textarea non-required. Update the occurrence of comment_form() in your theme file(s) to something like below (with custom args):
$comments_args = array( // change the title of send button 'label_submit'=>'Send', // change the title of the reply section 'title_reply'=>'Write a Reply or Comment', // remove "Text or HTML to be displayed after the set of comment fields" 'comment_notes_after' => '', // redefine your own textarea (the comment body) 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></p>', ); comment_form($comments_args);(2) To remove the comment textarea, remove the following line from the above code:
// redefine your own textarea (the comment body) 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></p>',Resource Links:
— https://codex.ww.wp.xz.cn/Function_Reference/comment_form
— https://www.inkthemes.com/how-to-easily-customize-wordpress-comment-form/
— https://premium.wpmudev.org/blog/customizing-wordpress-comment-form/I hope this helps.
Awesome, thanks for the help, I’m surprised that I missed that in the codex; guess I was too focused on removing the comment textarea altogether. Now the only problem I have is how to validate the URL. I thought I could use the input pattern below, but for some reason, it doesn’t appear to be working. If anyone has an idea why it isn’t working I would appreciate it.
$comments_args = array( // redefine your own textarea (the comment body) 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Video URL', 'noun' ) . '</label><input type="url" id="comment" name="comment" placeholder="https://youtu.be/example" pattern="https?://.+" required aria-required="true"></input></p>', ); comment_form( $comments_args );Actually, there is probably a WordPress way of doing this, plus I’m going to need to embed the video for playback anyways. Guess I’m just tired of working on this, really want to see it done and working, but I’m sure if I put in a little time I can get it figured out.
First, please mark the thread as Resolved as the original question is answered (and worked for you) already.
The correct pattern to validate youtube URL is:
^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$Hence, you can do something like…
$comments_args = array( // redefine your own textarea (the comment body) 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Video URL', 'noun' ) . '</label> <input type="url" id="comment" name="comment" placeholder="https://youtu.be/example" pattern="^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$" required aria-required="true"></input></p>', ); comment_form( $comments_args );Thanks again, but my point was that it doesn’t seem to matter what pattern I use, it doesn’t seem to have any effect. I’m not sure why, but it appears that I’ll have to use something build into WordPress to validate the URL. I’m not too worried about what URL people use because I should be able to adjust the embed for that, but I do want to know that it’s a URL at least.
Got to admit that this is getting out of my comfort zone, but it seems like I should be able to figure this out, but I do appreciate the help. Half of my problem is using the Twenty Fourteen theme; it seems like a good starting point for BuddyPress, but it has to be one of the more difficult themes to work with.
The topic ‘Remove Required Comment Textarea (Repost)’ is closed to new replies.
(@wpaddiction)
8 years, 4 months ago
Is there a way to make the comment textarea not required or remove it all together for a specific post type (moves)? I’ve done a bunch of digging, but I haven’t found anything that isn’t super hacky. It seems like there should be a function or something to change this. I know there are plenty of options to change the name and email fields, but I haven’t found anything to change the required comment field.
The only required field I want for comments is a video URL from YouTube or Vimeo because the plan is to make a public video contest where users will need to be logged in to post a video or vote on their favorite videos. I would imagine that other people have done similar things with videos and photos. (I’m looking at using the WordPress Comments Fields and the Comment Popularity plugins for some of those features.)
If there isn’t a good way to remove the comment textarea, I would at least like to be able to change the input type to a URL or another creative idea if anyone has one. Thank you in advance for any help.
The page I need help with: [log in to see the link]