• Resolved Jellico

    (@catsfoto1se)


    I’ve found a question on this site with the same headline, but that evolved to an plug-in.

    So I’m asking the same thing.
    What do I need to do, to let visitor leave a comment by only providing a name and the comment (eg. Remove the email & website questions)?

    I know that by adding this code:

    add_filter('comment_form_default_fields', 'unset_url_field');
    function unset_url_field($fields){
        if(isset($fields['url']))
           unset($fields['url']);
           return $fields;
    }

    to functions.php will eliminate the url question, but how do I remove the email question AND keep the name question?
    }

Viewing 1 replies (of 1 total)
  • Thread Starter Jellico

    (@catsfoto1se)

    Found a solution;

    1. Turn off the Comment author must fill out name and email in the settings/discussion on your WordPress panel.

    2. Add the following code (found on different sites and added them together)

    function remove_website_email_field($fields)
    {
     $fields = array( $fields['author']); //add $fields['email'] for only website field
     return $fields;
    }
    add_filter( 'comment_form_default_fields', remove_website_email_field );
    
    function require_comment_name($fields) {
     
    if ($fields['comment_author'] == '')
    wp_die('Error: please enter a valid name.');
     
    return $fields;
    }
    add_filter('preprocess_comment', 'require_comment_name');

    to your functions.php file in your themes directory.

    This will not only remove the email & website fields, it will also make the name field required even thou you turned it off in the settings.

Viewing 1 replies (of 1 total)
  • The topic ‘Hide email and website fields for comments?’ is closed to new replies.