0

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

2

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');
  • 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
1

try this:

add_filter('comment_form_default_fields', 'remove_email');
function remove_email($val) {
    $val['email'] = '';
    return $val;    
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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