Is it possible to remove the subject field on comment forms? I find it to be kind of useless and redundant, since the subject of the comment is usually the title of the article being read, at least for me anyway.
3 Answers
You can turn it off in the UI at admin/structure/types/manage/type-name
with the "Allow comment title" checkbox:
-
7Seems like they should rename "title" to "subject"... it would be less confusing. Thanks. Oct 1, 2012 at 22:20
-
In my case it is not possible to remove comment subject. Is it possible that there is a problem with other modules or after publishing some nodes this feature doesn't function? May 2, 2016 at 1:44
There I have found some solutions to this question.
Option 1:
How to disable comment titles in Drupal 7. This is so easy and good tutorial to simply hide the subject(title) of comment through user interface.
Option 2:
You can also use the hook_preprocess_comment() in template.php
file of your current active theme. This is really cool snippet, you can also some other options ie. comment-reply, comment-delete or comment-edit etc.
function bartik_preprocess_comment(&$vars) {
$vars['submitted'] = $vars['created'] . ' — ' . $vars['author'];
switch( $vars['node']->type ){
case 'macine-name-of-node-type':
$vars['title'] =FALSE;
break;
}
}
//get comment by node id
$comment->nid = $nid;
//get form by form name
$form = drupal_get_form('comment_form', $comment);
//hide subject in form
hide($form['subject']);
//check comment form
print render($form);
-
-
Hi Vivec, 4 lines of code are not really an answer. Can you explain where to place these lines? What function or hook? Jul 31, 2017 at 8:47