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.

I would like to remove the email field in the comment form. It works for url but not for email : the email field is still there. Do you know why?

<?php
function url_filtered($fields)
{
  if(isset($fields['url'])) {
    unset($fields['url']);
  }
  if(isset($fields['email'])){
     unset($fields['email']);
  }
  return $fields;
}
add_filter('comment_form_default_fields', 'url_filtered');
?>

Thanks

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

This works fine for me:

<?php
add_filter('comment_form_default_fields', 'wpse53687_filter_fields');
/**
 * Unsets the email field from the comment form.
 */
function wpse53687_filter_fields($fields)
{
    if(isset($fields['email']))
        unset($fields['email']);
    return $fields;
}

One reason that it could be failing on your theme is that args were passed into comment_form. Specifically, the theme author passed in a fields key into the $args.

As the filter name (comment_form_default_fields) implies, the fields are only defaults.

Fortunately there is another filter! comment_form_field_{$name}. Just hook in and return false and it should get rid of the email field.

<?php
add_filter('comment_form_field_email', '__return_false');
share|improve this answer
    
Thanks! it works perfectly! so is there any way to directly edit the code in the form? (without using these filters?) –  Paul May 30 '12 at 8:42
    
No, not really. The comment_form is usually what gets used in themes. –  chrisguitarguy May 30 '12 at 16:06
    
ok thanks Christopher –  Paul May 30 '12 at 16:46
add comment

try this:

add_filter('comment_form_default_fields', 'remove_email');
function remove_email($val) {
    $val['email'] = '';
    return $val;    
}
share|improve this answer
    
thanks t-p for the answer –  Paul May 30 '12 at 8:42
add comment

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.