Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
    
can you not also unset( $my_fields['url'] ); ? –  Milo Oct 7 '11 at 3:21
    
Yup, unset( $my_fields[ 'url' ] ); would blank it out as well as $my_fields[ 'url '] = NULL; –  Jeremy Felt Oct 7 '11 at 3:26
    
This code unfortunately did nothing for me. I am using a custom theme though so I may have to figure something else out I guess. –  jimmykup Oct 8 '11 at 19:33
    
Can you clarify what you mean by "this code did nothing"? If your custom Theme is using comment_form(), then this code is the correct approach. If your custom Theme isn't using comment_form(), then it should be. –  Chip Bennett Jan 18 '12 at 16:41
    
Changes like that should probably put into tiny plugins so that you are stable against core upgrade. –  Raphael Jan 18 '12 at 18:33

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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