Article

Drupal 7 Comment module: Remove default (Homepage, Subject) fields in tpl.php file

By default, Drupal's core Comment module displays core fields like Homepage, etc. There is no customizable setting from the Manage Comments area in your Content Type as these are already provided and outputted in the core template file. Exception for some fields like the "Subject" field. See instructions for removing the Homepage and the Subject fields separately below.

Drupal-7-Comment-Module-remove-default-fields-homepage-subject.png

To remove Homepage field

To resolve this in proper Drupal templating,

  1. In your themes/<your_theme>/templates/comment/comment-wrapper.tpl.php (copy this file from core /modules/comment/ to your template directory if not done yet), add code below before the HTML code or before the line code: <?php print render($content['comment_form']); ?>
  2. Flush all cache, then refresh page.

<!-- Remove homepage field hack -->
  <?php $content['comment_form']['author']['homepage'] = null; ?>
<!-- END, Remove homepage field hack -->

Alternatively, you can put this code in template.php of your theme:

function NAME_THEME_form_comment_form_alter(&$form, &$form_state) {
    $form['author']['homepage']['#access'] = FALSE;
}
"NAME_THEME" - replace on the machine name of the theme

To remove Subject field

On the other hand, to remove the subject field, there is a setting on the UI admin under the Comment settings of each of your Content Type.

  1. Navigate to your Content Type's Comment settings » Administration » Structure » Content types » Your Content Type 
  2. Click "Edit" tab of that Content Type
  3. Scroll down, then under "Comment Settings" tab, uncheck "Allow comment title", then Save.

    Drupal-7-Comment-Module-remove-default-field-subject.png