I'd like to remove the "subject:" field for posting new drupal comments. It's an optional field, but it displays the truncated body if it is left blank. I just don't have any need to display a subject for comments. Thanks.

Comments

styro’s picture

/admin/comment/configure

Look in "posting settings"

--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ

Steel Rat’s picture

Unfortunately I don't believe that's what the poster was looking for. At any rate it's not what I'm looking for ;)

I would much prefer that comments inherit the subject from the parent node by default, but still possibly allow the user to change it. So simply, when posting a comment, just insert "re: " + $node_subject, or something like that. Having a different subject for each comment is just contrary to what most people expect from forum or forum-like software. I find it INCREDIBLY annoying lol.

I would rather be able to do this within a template instead of changing core code.

Steel Rat
Drupal Site: RPGMapShare.com

styro’s picture

Unfortunately I don't believe that's what the poster was looking for.

I disagree :)

It sounded like they wanted to remove the subject line altogether.

At any rate it's not what I'm looking for ;)

True :)

I would much prefer that comments inherit the subject from the parent node by default, but still possibly allow the user to change it. So simply, when posting a comment, just insert "re: " + $node_subject, or something like that. Having a different subject for each comment is just contrary to what most people expect from forum or forum-like software. I find it INCREDIBLY annoying lol.

I agree, inheriting but still letting the commenter change it would be the best way of doing it for just about everyone.

I would rather be able to do this within a template instead of changing core code.

I don't think this is a template (ie theme) level problem. Solving it without altering core would really be a module level solution IMO.

The current bit of functionality seems to be here:

http://api.drupal.org/api/4.7/function/comment_form

<?php
  if (variable_get('comment_subject_field', 1) == 1) {
    $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 64, '#default_value' => $edit['subject']);
  } 
?>

The solution would probably be writing a module that uses http://api.drupal.org/api/4.7/function/hook_form_alter to prepopulate that form field.

Or course, a better longterm solution would be to create a patch against the core comment module that implements this and get it committed to core for Drupal 5.1/6.0 (whatever the version after next is called).

--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ

Steel Rat’s picture

I disagree :)

It sounded like they wanted to remove the subject line altogether.

Correct, which the admin setting doesn't do. It only prevents them from entering a subject of their own. :) I know, I tried :(

I found another post which does offer a theme template alternative, by editing the comment.tpl.php. I don't have the link to that post, unfortunately, that was a week ago. I used that information and successfully removed the subject from displaying on comments. Works like a charm.

Steel Rat
Drupal Site: RPGMapShare.com

seaneffel’s picture

No need to have specifics on the comment forms. The answer is to edit the PHP in your comment.tpl.php file (found in yoursite.com/themes/yourtheme/) to make the comment node look just the way you want. I found the

that contained my comment subject line and just deleted the whole thing. If you are new to editing theme template files then know that any of the theme PHP files can be changed to move elements around or assign different CSS classes as you wish.

Good luck.

Steel Rat’s picture

just deleting the whole comment subject may not be the right way to go. The subject is used as a page anchor when entering the page from certain aspects. If it works for you, that's great.

Steel Rat
Drupal Site: RPGMapShare.com

seaneffel’s picture

So maybe including the subject field in the tpl file but in a way this is not visible? That can be done. Then disabling the custom subject field in the cms would mean that the anchor is preserved and we get the apparent absence of the subject field on display. Am I thinking on the right track?

Steel Rat’s picture

That's pretty much what I've already done based on another thread. A date/time stamp is used in place of the subject as the comment page anchor. It makes for a much cleaner look to the comment listing.

Steel Rat
Drupal Site: RPGMapShare.com

jinks’s picture

Can you point to that thread, or possibly give directions on how you did this? I'd love to do this, especially for my forums.

xtedx’s picture

this is how i hide the subject text but still keeping the anchor:
replace
<?php print $title; ?>
with
<span style="display: none;"><?php print $title; ?></span>
in the comment.tpl.php file

Fayna’s picture

This didn't work for me in D6. :(

I instead gave that span tag a class of "comment-subject" and referred to it in my theme's style.css file giving it the "display: none;". That worked for me.

fumbling’s picture

Could you elaborate on how you made that work in D6? I'm a newbie to editing css and php files, but I can follow directions if they're specific enough. I also tried just adding the snippet mentioned above and wasn't able to get it to work in D6 so wanted to try your solution.

Fayna’s picture

In my comment.tpl.php file (if you don't have one create one), I put this:

<span class="comment-subject"><?php print $title ?></span>

I just put a span tag of comment-subject around the comment's title. Find your <?php print $title ?> tag and put my code around it.

Then I went into my theme's .css file, and created this span tag there as well:

.comment-subject {
	display: none;
}

Technically you can name "comment-subject" to anything you want but I chose that to help me remember what it is for. :P It should probably be an ID instead of a class tag but since a comment title shows up for each comment(s) I wasn't sure.

tanma’s picture

I also want to hide the subject (v6) and tried your code Fayna, but for some reason it didn't work.

I am updating a custom theme in \sites\all\themes\tania and followed your instructions. But I suspect there is something else I need to do as I tried some other simple changes and they didn't seem to be reflected on my site. Do I need to refresh something?

Sorry, I'm new to the Drupal scene (would also like to modify the author date/time - to left align, change some of the text). Any help would be greatly appreciated.

fumbling’s picture

I was finally able to get this to work a while back. I checked my notes. All I did was to remove the following from comment.tpl.php

print $title

Drupalot.com - ask & answer Drupal questions

tanma’s picture

Steel Rat above mentioned

just deleting the whole comment subject may not be the right way to go. The subject is used as a page anchor when entering the page from certain aspects.

There seems to be a few ways to do it (ie. I've come across various snippets) but the real problem I have is that any changes I made to the comment.tpl.php doesn't seem to have any effect what so ever - am I modifyingin the wrong place? - need to refresh something??

tanma’s picture

A classic gotcha (http://drupal.org/node/238812#comment-792683)
I forgot to clear the cache!

I found the the code suggestion of xtedx was the only one that worked for me (even works in 6.2).

drupalot, I didn't remove it as you suggested as I was worried it would play havic with the recent comments block? (actually I not sure at all on that). Still thanks for your help - it was appreciated.

fumbling’s picture

No problem. Glad you got it working. I may try xtedx solution as well, as there are some weaknesses to the approach I took. Best!

Drupalot.com - ask & answer Drupal questions

mattwmc’s picture

I am trying this now.

I removed that from both the comments mod - comment.tpl.php and my theme which has a comment.tpl.php and the subject line is still there.

Where would it be coming from?

devillized’s picture

im not sure whether changing Spans to divs will be frowned upon or not, what matters is that it worked.

just replace "span" with "div" in fayna's code and follow the remaining instructions. Works fine.

robclay’s picture

xtedx's post on May 16, 2007 - 07:39

this is how i hide the subject text but still keeping the anchor...

Worked fine for me! Thanks

zapa’s picture

Drupal 6

Do this...

Go to modules/comment edit comment.tpl.php

Replace <?php print $title; ?> with <span style="display: none;"><?php print $title; ?></span>

Go to your template find comment.tpl.php replace Replace <?php print $title; ?> with <span style="display: none;"><?php print $title; ?></span>

if there is no <?php print $title; ?> go to theme/your_theme find template.php and inside it locate <?php print $title ?> replace it with <span style="display: none;"><?php print $title; ?></span>

now

go to theme/your_theme opern up your .css file and add at the end

.comment-subject {
	display: none;
}

it should work

it doesen't look into your theme file for this line: <?php print $title; ?> be sure that is from comments and replace it with <span style="display: none;"><?php print $title; ?></span>

realityloop’s picture

@zapa, This is the wrong way to do this, you should be copying that tpl file to the directory of your theme and editing it there.

mErilainen’s picture

Is there a way to check if the node type has comment subjects enabled and then decide if to show them or not?
These tips here disable the comment on every node, so I cannot use the subject for any node type even if I want to.

jwatt’s picture

To remove the comment field:

Administer > Content management > Content types

Click on a content type.
Expand the "Comment settings" area.
Change "Comment subject field" to disabled.

shaunak’s picture

That only prevents the user from entering his custom subject line. Drupal still makes up the subject line from the body of the comment.

seaneffel’s picture

Disable the subject field in the admin settings like above, then edit the template file in your active theme to remove the comment from display. That's the way you'll have to do it until we make theming a point and click operation.

You will be looking in your theme directory to find a file called comment.tpl.php, find the line that renders the subject or title variable and delete it and any tags enclosing that line. Make a backup of the file first.

arhak’s picture

this old thread seems to have some activity yet
therefore I would suggest you trying comment_subject (6.x-2.x branch) which will allow you to decide how should subjects be generated (whether they are disabled or not), nevertheless this won't change the theme template which renders it, but still can be forced to be something more appropriated (like leave it completely empty)

David Latapie’s picture

Did you mean http://drupal.org/project/comment_subject? If yes, then this is still not perfect, as it doesn't allow to remove the subject line altogether (which is basically what most people here want).

IMHO, comment subjects (the feature, not the module) is a good candidate for the top 10 misfeatures.

arhak’s picture

as I said, it won't stop rendering it, that can be done on template files (theme files)

IMO, that misfeature is backed up by good rationales (at the time, and it seems to remain in D7)
nevertheless, I do agree it becomes annoying when you really/badly wan't to get rid of it

mak777’s picture

In Drupal7, you can disable "Subject" field in Comment as follows :

1)
Go to >>
>> Structure
>> Content types

2)
On Content types screen >>
>> Click "edit" link of the content type (for example, Article) of which you want to disable "Subject" field in Comment

3)
On Article - Edit Pane >> Below "Name" and "Description" field, there are several links for different kind of settings. From them >>
>> Click on "Comment settings" link
>> Uncheck "Allow comment title" check-box
>> Click on "Save content type" button to save your settings.

If you want to disable "Subject" filed in all your content types (i.e. Article, Basic page, Blog entry, Book page etc.) you will need to click edit link of each content type one by one and need to follow the steps suggested above in (3), on each content type's edit pane respectively.

~~ Murtaza Kapaasi

ttjordan81’s picture

This works! To add to this if you already have subject titles on your page. Just go to styles.css file and find comments titles and add display:none;

jag339’s picture

Go to:
Administration » Structure » Content types » My Content Type
Click "comment fields"
You're not allowed to delete the Subject.
I can appreciate everyone saying go to the comment.tpl.php page or styles.css and just hide the comment itself, but I don't even want the widget there. I don't want users to have to enter a subject at all.

arhak’s picture

do both:

go to admin/.../... as they said, and disable the comment field there,
with this, users won't be presented with a textfield to input a subject, but Drupal still will generate one (from the first words of the comment body)

then do the comment.tpl.php edit, as suggested, which will actually get rid of it, once and for all

the first step is to take it out from the backend
the second step is to remove it from the frontend

ashrafabed’s picture

-- Correction, check the comments below mine.

jessicakoh’s picture

You can disable. Are you sure?

stephen Verdant’s picture

Yes, Go to:
Administration » Structure » Content types » My Content Type

But the option is not in Content Fields, it's under Edit, in the accordian for Comment Settings, unclick: Allow comment title

payamspot’s picture

So easy, but i didn't realize :)

Thank you so much stephen Verdant.

cq92’s picture

After some hunting and trying to find a config section for "comments" content - it turns out there is a really easy way to disable the subject on comments.
1. go to admin and content types.
2. select the content type you want to modify eg: page or images
3. Scroll nearly to the bottom where it says comment settings.
4. Comment subject field - check disabled.

And as a note - you can disable all comments, disable anonymous or require anonymous visitors to leave their email and control if the comment is done on the same page or opens in a new window. Unfortunately you have to set each content type separately - there is no place to do one setting for all comment forms.