Can I change what fields are displayed in the Comments form?

Is it possible to change the fields that are available in the comments form? By default my comments form is asking for Name, Email, Website, and then the actual message. I’d like to remove website and replace it with a new field of my choosing.

What’s the best way to accomplish this?

Related posts

Leave a Reply

2 comments

  1. This answer can change depending on the theme or plugins you have installed, but the code can usually be found in similar places of the theme editor.

    For example, if you are using the default Twenty Eleven theme in WordPress 3.2.1, you can verify the location of the comments call by checking here:

    1. Login to your admin interface.
    2. Click on the Appearance menu.
    3. Click on Editor under Appearance.
    4. Click Comments on the right side to edit the comments.php file.

    This will bring up the page that WordPress uses to generate the comments display.

    Some themes may have entered code that you can edit directly to change the display. Twenty Eleven uses the default WordPress function ‘comment_form()’ to display the form used for new comments.

    A lot can be done to change the values at this point, and you should take a look at the full documentation of comment_form() for all of the details. To get you started though, click on Theme Funcitons on the right side to open the functions.php file and add the following at the bottom:

    // This creates a filter to change the default comment fields.
    add_filter('comment_form_default_fields', 'my_comment_changes'); 
    
    function my_comment_changes ( $my_fields ) {
        $my_fields[ 'url' ] = ''; //This will make the website area display nothing.
        $my_fields[ 'custom' ] = 'test field only<br>'; // This will add a custom field.
    
        return $my_fields;
    }
    

    It can definitely get more complex than that if you need it to, but this will get you started.

  2. Way to add a new field…

    add_filter('comment_form_default_fields', 'new_fields');
    
    function new_fields($fields)
    {
        $fields['my_field'] = "<input type='text' name='my_field' />";
        return $fields;
    }
    

    Apologies, but I don’t have an idea how to save the new field.