Support » Plugins » Hacks » Remove text field from comment form

  • Resolved edow



    I would like to remove the text field from the comment form. The idea is that users can vote if they like the post or not. The like/unlike option must be done with radio buttons in a custom field (that would be the next problem).

    But first: How can I remove the text field? I don’t want it hidden, but entirely removed. What is the best practice for this? I can’t find a decent solution.

    Hopefully anyone can help me with this.

Viewing 15 replies - 1 through 15 (of 49 total)
  • Are you looking to do this on your site alone or make a plugin that is reusable across multiple sites? What theme are you using? How are you displaying the comment form? Are you just using the comment_form template tag?

    There’s ways to do this, but it really depends on your exact setup.


    I want to do this on one site only and I made the theme myself.
    I use <?php comments_template(); ?> to display the form. So I think it’s the same?

    comments_template simple sets up some variables and includes a template file (probably comments.php in your theme). The form is usually generated by the comment_form template tag which has a bunch of things you can override.

    For your purposes, you probably just need to find where the comment_form template tag is used and pass the correct arguments to it. Something like:

    comment_form(array('comment_field' => '<input type="hidden" name="comment" value=" " />'));

    That basically says, replace the textarea (which is the default value for comment_field) with a hidden input that contains a space character so that the comment isn’t empty.

    Whether or not this works from that point forward is a question of whether WordPress allows almost empty comments. You should be good to go for the most part, though.

    For adding additional elements to the comment form, you can hook to one of the following actions:

    • comment_form_before
    • comment_form_must_log_in_after
    • comment_form_top
    • comment_form_logged_in_after
    • comment_form_before_fields
    • comment_form_after_fields
    • comment_form
    • comment_form_after

    Your best bet is to just open up /wp-includes/comment-template.php and figure out where there are hooks available to modify the behavior you want and take advantage of them. Best of luck!

    Thank you for your response. Tomorrow I’ll take a look at this. Thanks in advance!

    My comment_form tag looks like this:

    <?php do_action('comment_form', $post->ID); ?>

    I’m not sure how to use your line of code, because the form doesn’t show anymore after I use your code within my code. I think I’m doing something wrong.

    If it will work, doesn’t the database get full of code of tags (?) with whitespace? I’m not sure how this works, but I suppose the space from the textfield is saved in the database?

    Sorry for my bad English.

    edow – I’m sorry, but I can’t help you any further at this point. If you have do_action('comment_form', $post->ID) then you probably have a form hardcoded into your comments.php file. If that’s the case, simply remove the textarea tag and see if that works. Beyond that, I recommend contacting a WordPress developer who can take on small jobs like this.

    I appreciate your quick replies.

    I’ve managed to remove the text field, because (as you said) it’s hardcoded.

    This is my code now:

    <div class="comment">
    					<label>Review: (verplicht)</label>
    					<input type="radio" name="comment" id="comment" value="like">Like<br>
    					<input type="radio" name="comment" id="comment" value="unlike">Unlike
    					<br />
    					<input type="submit" class="commentsubmit" value="Review plaatsen" />
    					<?php if ( is_user_logged_in() ) { echo ''; } else { echo '<span> - Het is niet verplicht, maar je kan een <a href="">gratis profiel aanmaken</a> of <a href="'.wp_login_url( get_permalink() ).'">inloggen</a></span>'; };?>

    I also made radio buttons as you can see. The problem now is that it says “Your comment is awaiting moderation.” and I can only place one review. Maybe because it’s from the same IP.

    Now it works. In the WordPress settings I changed the option that the user must have a previous approved review. It looks like it works well.

    The next problem is that I want to sort the people in two lists. One list with people who choose “LIke” and a list of people (avatars shown only) who choose “Unlike”.

    Hello, i was just saw this about comment so im try to ask you here. For a while ago I made a site to a guy that had try to do it by himself, hes mistakes was he let anyone register as (administrator) instead of authour. When he contact me i removed a hacked link into main template of hes site and i thought that was enough but still even i make a sign up as auhour and want to leave a comment on hes food recipes i cant do that.

    this is hes website: and its impossible for me atrleast to leave comment but i see that now after few days he got several other ppl logged in and register as authour but as what i see no comments only one had did one comment and i cant allow that comment coz i know thats a hacking person…

    What should i do to fix this error on hes comment section.

    OK next Questian..
    Im adding few social plugins on hes website, im kinda new onb doing that coz before i never add those stuff not even on mine…

    BUt however, hes website is simular to a women website also foods but different country and taste…

    Google plus on her site i can see a big picture of some foods and her profil picture in google plus and the circle following thing, he want like that on hes but the plugin i was choose seems not allow that and im not sure what to do here to help him… he had just hes profile picture there. this is the french women site and this is my friends site….

    hoping to get some help here

    Moderator bcworkz


    Hello Media2U,

    If a hacker had access as administrator, there is a good chance he installed a hidden backdoor somewhere on the site. These can be extremely difficult and time consuming to find and successfully remove. It’s usually best to wipe the entire site and restore it from a known clean backup. See FAQ My site was hacked.

    FYI, tagging onto someones topic is frowned upon in these forums. Please start your own topic so your issue can be fully addressed without being confused with other answers. I also suggest you focus on one issue per topic, an expert in hackers may know nothing of social media or vice versa, so he may be reluctant to help you since he cannot fully address all your issues. A focused topic will more likely get you a focused answer.

    I’ve still my question. Is it possible to sort the comments in two lists? Comments can only contain the word “like” or “unlike”. Is it possible, based on these words, to sort these comments in two seperate lists? One list with the “likes” and the other one with the “unlike”. In this list only the avatar should be shown. Hopefully anyone can help me with this.

    Moderator bcworkz


    Sorry edow, I didn’t realize you still had a pending question.

    Yes you can sort comments as you envision. The specifics depend on how your theme handles comments, exactly how the vote selection is stored, and your coding abilities. There’s a number of possibilities. You could do a single query, ordered by the vote field. The comment loop would detect when the votes change and start a new list. You could do two separate queries. You could use a single query and sort the results using PHP, either as part of the comment loop, a user array sort, or part of a walker function. There’s probably hybrid variations of any of those approaches.

    Hi bcworkz,

    No problem and thanks for your reply!

    These are the input fields for the like/dislike buttons in the comment section:

    <div class="comment">
    					<label class="commentformtitle">Do you like <?php the_title(); ?>?</label>
    					<span class="radiobuttonleft"><input type="radio" name="comment" id="comment" value="like">I like this!</span>
    					<span class="radiobuttonright"><input type="radio" name="comment" id="comment" value="unlike">I don't like this...</span>
    					<input type="submit" class="commentsubmit" value="Submit review" />

    My coding abilities aren’t so well. I’m not sure how to achieve this. Is it possible that you help me a little bit further with this?

    The comment form itself works good. Guests have to input their name, email and choose like or unlike. After submit the comment text is “like” or “unlike” so that works great.

    I realy don’t know how to handle this. In the database the comment text only saves “like” or “unlike”, so perhaps with PHP I can sort the likes and unlikes based on the comment-text? Hopefully you can help me a little bit further.

    Moderator bcworkz


    So there aren’t any true comments with authored words, the entire comment text will either be “like” or “unlike” and nothing else? That certainly simplifies things if so. Do you just need a count of each vote, or do you actually want a list of who voted one way, then those voting another way?

    Which approach would make the most sense somewhat depends on the scale of the site. Small sites can do almost anything without consequences. Huge sites must carefully consider every approach. What scale do you ultimately see for this site? How many comments per post? Dozens, hundreds, thousands? Same for how many posts eventually.

    I generally don’t code for people except in way of illustrating a point or something simple and short. You may fall into the latter category if I understand your situation correctly. Unfortunately, I’m under a major time crunch for the next few days. (and currently have no access to my usual development tools) I can probably help you out in a few days if no one else jumps in before hand.

    Yes you’re right, the entire comment text is “like” or “unlike”. There is no text field, only the radio buttons and the input field for your name and email address.

    I want a list with people who voted “like” and a seperate list of people who voted “unlike”. I have two lists like this:

    `<div class=”upvoters” id=”votes”>
    <h2>We like this!</h2>
    <div class=”voter-img”>
    <a href=”#respond”><img src=”/wp-content/themes/aigooNL/images/upvote.png” class=”upvote”></a>
    <img src=”/wp-content/themes/aigooNL/images/voter.png” class=”tooltip” title=”John”>
    <img src=”/wp-content/themes/aigooNL/images/voter.png” class=”tooltip” title=”Edo”>
    <img src=”/wp-content/themes/aigooNL/images/voter.png” class=”tooltip” title=”Peter”>
    <img src=”/wp-content/themes/aigooNL/images/voter.png” class=”tooltip” title=”Joey”>

    <div class=”downvoters”>
    <h2>We, not so much…</h2>
    <div class=”voter-img”>
    <a href=”#respond”><img src=”/wp-content/themes/aigooNL/images/downvote.png” class=”downvote”></a>
    <img src=”/wp-content/themes/aigooNL/images/voter.png” class=”tooltip” title=”Chris”>
    <img src=”/wp-content/themes/aigooNL/images/voter.png” class=”tooltip” title=”Michael”>

    There are two classes: upvoters and downvoters. These lists reflects the votes.

    I have a small website. Sure, I want the site to grow, but right now I’m thrilled if someone gave a review 😉
    Hopefully the site will grow and I get dozens “likes/unlikes” on each post, but certainly not thousands.

    I understand if you don’t have the time to help me with this, but I would really appreciate it if you or someone else could help me a little bit more. I understand how to design and know about html, but I don’t know much about PHP or other coding languages.

    I’m not in a hurry. If you need more information please let me know. Thanks already for any help you can give.

Viewing 15 replies - 1 through 15 (of 49 total)
  • The topic ‘Remove text field from comment form’ is closed to new replies.