I'm new to Drupal, and have been struggling to figure out how to remove the title field/link from comments in Drupal 7. I'd like to completely remove the option to create or display it. Any help would be appreciated. I think I've exhausted searches on Bing and Google. :)

Comments

spurrdog’s picture

Hi,

Not sure if this is exactly the same in 7.x but in drupal 6 just edit the Content Type by going to admin/content management/content types. Select the content type you want to change ie. Page. You will see under Comment Settings there is an option to disable subject field.

Maung Maung’s picture

In Drupal 7, the comment title setting is under "admin/structure/types/manage/[CONTENT TYPE]/edit" -> "COMMENT SETTINGS" region.
You can check/uncheck the "Allow comment title" for that content type.

Change the [CONTENT TYPE] for your target content type.
Hope this help for you.

89121’s picture

I have this option disabled. It disables the ability to create a comment title, yet a default title is still displayed consisting of the first few words of the comment.

heystswede’s picture

You need to remove some lines of code from your comment.tpl.php file which is located at: [your_site]\themes\[your_theme]\templates\comment.tpl.php

remove or block this lines:

<?php print render($title_prefix); ?>
<h3<?php print $title_attributes; ?>><?php print $title; ?></h3>
<?php print render($title_suffix); ?>

This works for me as far as I'm using bartik, for other themes could be different.

89121’s picture

It does not appear that this will work with my base theme (basic).

I removed the block displaying formatting options using the following code:

<?php hide($content['comments']['comment_form']['comment_body']['und']['0']['format']); ?>
<?php print render($content['comments']); ?>

I was thinking there would be a similar method of suppressing the output of the comment title. I just have not been able to determine how I can find the correct elements or syntax.

Nico7’s picture

Worked with Bartik. Great!

brachameansblessing’s picture

I am using "fresh" theme. Here is the code below. What part of the code can I change into a comment so that default titles do not appear on my comments. Also, will this affect the behavior of the posts on my discussion board?

Thank You!

print $classes; " print $attributes; >
if ($content['comments'] && $node->type != 'forum'):
print render($title_prefix);

print t('Comments');

print render($title_suffix);
endif;

print render($content['comments']);

if ($content['comment_form']):

print t('Add new comment');

print render($content['comment_form']);

endif;

rxg’s picture

Hi. New to Drupal and PHP, so I can't guarantee that this is a good idea. That being said, I have two different content types, one where I want subjects and the other where I do not. Another way to look at it: I don't want subjects if I don't need subjects. Since Drupal auto-generates comment subjects that are a prefix of the comment itself, a fast-and-dirty fix (inspired by the above) was to check *that* and print the subject conditionally. So I replaced the <?php print $title; ?> bit above with:

<?php
      $subj = $content['comment_body']['#object']->subject;
      $body = $content['comment_body']['#object']->comment_body['und']['0']['value'];
      if (0 != substr_compare($subj,$body,0,strlen($subj))) {
        print $title;
      }
?>

It grabs the subject, and the comment body and compares them, only printing the title if the subject is not a prefix of the comment itself. The bad part of this is that it will also hide the comment if the user happens to write a subject that is a prefix of the comment. I'm willing to live with that though ;).

Anonymous’s picture

Do you know what lines of code to remove in Drupal 8 to remove the comment subject in the Bartik theme? I am new to Drupal and don't see anything with "print render" in the comment template.

NonProfit’s picture

Hi lsnyders,

The comment title is rendered in line 103 of core/themes/bartik/templates/comment.html.twig. However, you never want to modify anything in the /core folder. Instead, create a subtheme, declare Bartik to be the base theme, and modify the comment.html.twig template there.

89121’s picture

Found my answer and will post it in case someone is searching for this so that they find the solution. It was simple enough, not sure why I didn't find it sooner.

I just commented the print statement in the comment.tpl.php within my theme. Live and learn. Everyone must be a noob at some point.

<!-- <?php print $title ?> -->

earwax’s picture

It's too bad that you have to do this on the theme layer. I guess to make it fancier, you could show the title/subject if the user wants to have a title/subject.

For example,

<?php 
if($title != '') {
  print $title;
} 
Leo Jiménez’s picture

It is a good idea, but the variable $title is not empy, it have some autogenerate string. We need another variable

Ron Collins’s picture

If you don't already have a comment.tpl.php, you can add this to your style.css:

.commentTitle
{
display: none;
}
jaxon77’s picture

I have disabled comment titled for a content type and they no longer show, but in the database the comment subject title field is still being filled with the comment body which can cause problems with the template is only checking if it is empty. Why is the subject field still being populated with data?

Jeff Burnz’s picture

Probably because you can turn it on again later if you change your mind.

cfischer50’s picture

Thanks for posting!! I enabled Custom CSS in my Theme settings (subtheme of Adaptive Theme) and added this:

.forum-post-title
{
display: none;
}
Elijah Lynn’s picture

If you are using Display Suite on your site, then it can do this for you.

www.drupal.org/project/ds

-----------------------------------------------
The Future is Open!

bond708’s picture

to administer the comment settings on content type level.
Admin -> structure -> content type -> blog-item -> edit
In the menu click on comment settings

AlfTheCat’s picture

For me, adding the following CSS to my main stylesheet did it:

.permalink {
    visibility: hidden;
    display: none;
}

----
"People make mistakes. To really mess something up you need a computer."

fraweg’s picture

Hi,

when i hide the comment title and I use the opera browser the complete body is also gone :-( Any Idea how to solve this issue?

Best regards
Frank

Graham Leach’s picture

There's an error in Drupal Core with respect to comments.

In the Administrative interface, under Comment settings, there is a check box labeled:

O Allow comment title

This is wrong.  It should actually read:

O Allow comment subject line

That way, when people are looking to modify/delete this setting it's easier and more intuitive for them.

There are several ways to make this thing (comment::subject) go away.

1.  First, How About Some Naming Harmony?

First, name it properly so people can find it and discuss it more meaningfully.  It's "subject" not "title".

2.  Through the Administrative Interface

You can use the Administrative Interface to prevent it from being displayed  

Go to:  admin/structure/types/manage/<content_type> and adjust its settings. 

In my case, I wanted to remove the need for a subject line for a product review (which uses comments), so I went to:

admin/structure/types/manage/product

- I looked for the Comment settings area, near the bottom of the page
- I unchecked "Allow comment title"
- I clicked on Save content type

3. Through Cascading Style Sheets

You can use CSS to prevent it from being displayed

Open up a comments form on your computer, wherever it appears on your website

Right-click on the field and select "Inspect" (if you are using the Chrome browser)

Make sure you are looking at the right element of the page and take note of its class or id 

To test your guess as to the element name, type display: none; in a new line between the curly braces in:

element {

}

If it goes away, you've probably found the element you need to modify in either your theme.css or custom.css file.

finding the above files requires that you root around in the following directories, depending on whether you have created a sub-theme or not:

/sites/all/themes/<theme_name>/css/theme.css

or 

/sites/all/themes/<theme_name>/<subtheme_name>/css/custom.css

4.  Through Altering Existing Programming

You can modify existing programming to prevent it from being displayed.  How a theme looks, feels and behaves is highly influenced by the *.tpl.php files that define it.  In some cases, themes implement comments differently.  In some cases they hard-code comments functionality.

The way to find hard-coded functionality is to

- Make note of the string you are looking for

- Navigate to the root of your Drupal installation

- Issue the following command at the root of your Drupal installation

$ grep "<comment_string>" * -R

- Review the list of string occurrences

At that point you can choose whether or not to modify what you've identified as the offending line of code

5.  Through New In-line Programming

You can add programming that will prevent it from being displayed

In the *.tpl.php file, you can add lines of code that will prevent a comment subject from being displayed.

An excellent article that covers this exists at:

https://www.digett.com/insights/how-theme-comment-form-drupal-7

Here's some code from that article, in case it vanishes (full credit to Art Williams)

Posted by Art Williams on May 26, 2011

Here is the entire override function containing all of our changes (replace THEMENAME with your own theme’s name) and a screenshot of the resulting comment form.  Copy and paste this into your template.php file and start theming away on that comment form.

function THEMENAME_form_comment_form_alter(&$form, &$form_state) {
  //dpm($form);  //shows original $form array
  $form['author']['#type'] = 'fieldset';
  $form['author']['#title'] = 'Your Information';
  $form['author']['#collapsible'] = FALSE;

  $form['your_comment'] = array(
    '#type' => 'fieldset',
    '#title' => t('Your Comment'),
    '#collapsible' => FALSE,
    '#weight' => 2,
  );

  //Subject
  $form['your_comment']['subject'] = $form['subject'];
  unset($form['subject']);
  $form['your_comment']['subject']['#weight'] = -10;

  //Comment
  $form['your_comment']['comment_body'] = $form['comment_body'];
  unset($form['comment_body']);

  $form['author']['homepage']['#access'] = FALSE;

  $form['author']['mail']['#required'] = TRUE;

  //dpm($form);  //shows $form array after our changes

}

6.  Through Creating a New Module

You can write a program that will prevent if from being displayed

This is using artillery to swat a fly, but it is possible to create a custom program that will make the title field of a comment go away.

I am not going to get into this here, because explaining how to create a custom modules is weighty enough to justify another article.

Have a look at the following modules (that affect Comments) to see how it has been done:

- Better Comments (better_comments) at https://www.drupal.org/project/better_comments

- Comment Goodness (comment_goodness) at https://www.drupal.org/project/comment_goodness

- Comment Hide Subject (comment_hide_subject) at https://www.drupal.org/project/comment_hide_subject

N.B.:  If you are interested in learning Drupal module development, comment_hide_subject is about as basic as a module gets