
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:
- By putting your custom code into template.php file
- 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:
function ModulNameOrYourThemeName_form_comment_form_alter(&$form, &$form_state, &$form_id) {
$form['comment_body']['#after_build'][] = 'ModulNameOrYourThemeName_customize_comment_form';
}Option A) If you only want to hide formatting guidelines and Filter Tips link, then add this function to the file:
function ModulNameOrYourThemeName_customize_comment_form(&$form) {
// Hide guideliness
$form[LANGUAGE_NONE][0]['format']['guidelines']['#access'] = FALSE; // Note ‘und’, you may need to set your comment form language code instead
// Hide Filter Tips
$form[LANGUAGE_NONE][0]['format']['help']['#access'] = FALSE;
return $form;
} Option B) If you want to hide all format options, then add this function to the file:
function ModulNameOrYourThemeName_customize_comment_form(&$form) {
$form[LANGUAGE_NONE][0]['format']['#access'] = FALSE; // Note LANGUAGE_NONE, you may need to set your comment form language code instead
return $form;
} 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!

Comments
Submitted by vikky on Mon, 07/11/2011 - 01:13
Although it works partially, I am unable to remove "More information abut text formats". How do I remove that?
Thanks a lot!!
Submitted by Tim on Mon, 07/11/2011 - 10:41
Please see "Option A" function updated.
Submitted by dalin on Mon, 07/11/2011 - 08:59
Or the easier, more maintainable option:
http://drupal.org/project/better_formats
Submitted by Tim on Mon, 07/11/2011 - 10:29
I know about this module, but for doing this simple thing I don't want to install another module.
Submitted by EvanDonovan on Tue, 07/12/2011 - 01:39
Was there a particular reason you used #after_build instead of just hook_form_alter? Worried about some module later in the execution order clobbering the changes?
Submitted by Tobias on Wed, 11/23/2011 - 02:08
Dear Tim,
your instructions are exactly what I need, however it does not work for me!
Here is the code in my module invitation:
function invitation_form_comment_form_alter(&$form, &$form_state, &$form_id) {
$form['comment_body']['#after_build'][] = 'invitation_customize_comment_form';
}
function invitation_customize_comment_form(&$form) {
$form[LANGUAGE_NONE][0]['format']['#access'] = FALSE;
return $form;
}
Seems to me like I copied it correctly. I do not manage to get an output of the comment form via drupal_set_message in this hook, so I am struggling with the debugging. Can you advise me how I can find the mistake in my case, please??
Thanks a lot, Tobias
Submitted by Kannary on Wed, 12/28/2011 - 04:33
Another option is to use the awesome MyHook Administration module, in which case you can inject module-level hooks anywhere:
http://drupal.org/project/myhook
If using this module, then add the functions like such:
//Remove Formatting Tips and Links from Comments
function myhook_form_comment_form_alter(&$form, &$form_state, &$form_id) {
$form['comment_body']['#after_build'][] = 'myhook_customize_comment_form';
}
function myhook_customize_comment_form(&$form) {
// Hide guideliness
$form[LANGUAGE_NONE][0]['format']['guidelines']['#access'] = FALSE; // Note ‘und’, you may need to set your comment form language code instead
// Hide Filter Tips
$form[LANGUAGE_NONE][0]['format']['help']['#access'] = FALSE;
return $form;
}
Submitted by Angelo on Thu, 01/05/2012 - 11:55
I have no comment form but in order to "remove" the "more information about text formats" link in my admin theme I ended like this in my theme css:
.filter-help{display: none;}
Submitted by fourmi4x on Fri, 01/06/2012 - 01:02
Thanks for sharing this, exactly what I was looking for !
Submitted by jkool on Sat, 01/14/2012 - 17:01
Works fine for comments, but how on earth do I remove this for the "text format" stuff for the node itself?
Submitted by blackangelxl on Fri, 01/20/2012 - 11:00
Take this:
/**
* Function - yourthemename_form_comment_form_alter.
*
* @param array $form
* @param type $form_state
* @param type $form_id
*/
function yourthemename_form_comment_form_alter(&$form, &$form_state, &$form_id) {
$form['comment_body']['#after_build'][] = 'yourthemename_customize_comment_form';
}
/**
* Function - yourthemename_customize_comment_form.
*
* @param type $form
* @return boolean
*/
function yourthemename_customize_comment_form(&$form) {
$form[LANGUAGE_NONE][0]['format']['guidelines']['#access'] = FALSE;
$form[LANGUAGE_NONE][0]['format']['help']['#access'] = FALSE;
$form[LANGUAGE_NONE][0]['format']['#attributes'] = array('style' => 'display: none;');
return $form;
}
Add new comment