How To Remove Format Options / Guideliness From Comments Textarea in Drupal 7

The task is very common, but in Drupal 7 you do this in a bit different way than in Drupal 6. Here’s how to remove format options from comments textarea in Drupal 7: UPD: Well, the most easiest way to do this is to install Better Formats module (http://drupal.org/project/better_formats). But do we need another module installed to do this simple thing? Me, not, so let's dig into the code a bit. Basically, we need to alter comment form.

You can do this in two ways:

  1. By putting your custom code into template.php file
  2. By putting your custom code into your custom module

It’s up to you which way to choose. If you want your changes to be applicable not only to the active theme, then choose the second option. Ok, now, depending on a way you’ve chosen, add this code to your template.php or module_name.module file:

  1. function ModulNameOrYourThemeName_form_comment_form_alter(&$form, &$form_state, &$form_id) {
  2. $form['comment_body']['#after_build'][] = 'ModulNameOrYourThemeName_customize_comment_form';
  3. }

Option A) If you only want to hide formatting guidelines and Filter Tips link, then add this function to the file:

  1. function ModulNameOrYourThemeName_customize_comment_form(&$form) {
  2. // Hide guideliness
  3. $form[LANGUAGE_NONE][0]['format']['guidelines']['#access'] = FALSE; // Note ‘und’, you may need to set your comment form language code instead
  4. // Hide Filter Tips
  5. $form[LANGUAGE_NONE][0]['format']['help']['#access'] = FALSE;
  6. return $form;
  7. }

Option B) If you want to hide all format options, then add this function to the file:

  1. function ModulNameOrYourThemeName_customize_comment_form(&$form) {
  2. $form[LANGUAGE_NONE][0]['format']['#access'] = FALSE; // Note LANGUAGE_NONE, you may need to set your comment form language code instead
  3. return $form;
  4. }

Save your file and don’t forget to clear Drupal’s cache (Configuration > Development > Performance > Clear All Caches).

That’s all for now, enjoy and happy drupalling!