Community & Support

Remove "Add Comment" from Teasers?

Is there any way to remove the "add comment" link from teasers?

I dont think it makes sense for people to comment on something they havent read yet.

Thanks

Comments

brute force way

In comment.module find the section that starts:

    if ($teaser) {
      // Main page: display the number of comments that have been posted.

comment out everything inside of the if statement.

This potentially makes it confusing if the teaser is the entire post, since a user would have to click "read more" to add comments when there wasn't anything more. You could change the "read more" text to be "Read more or add a comment" or something like that.

Well

Well, I was hoping there was a way to do it only if the teaser was not the full post, and in a way that did not involve modifing the core code. I think for now I will leave it the way it is, but I do appreciate your response very much.

Thank you.

No confusion

The users won't know there is no more to read until they're already there. But then they will find the add comment option.

I started with Drupal in 2007 and then my life got stuck...

Try to insert this in

Try to insert this in template.php of your theme:

function phptemplate_links($links) {
  if (count($links)>0){
    if (isset($links[node_read_more]) && isset($links[comment_add])){
    unset($links[comment_add]);
    }
  }
  return theme_links($links);
}

Tested with Drupal 6.9 Garland theme.

unset($links[comment_add]); does not work

I have tried this with phptemplate_links (generates errors) and themename_links (no errors but does not change output)... not sure why sorry :-)

Need to clear cache

Parent function works. You just need to flush cache before the function is activated.

Fix

The above code has more than a few error - namely, the function name and no string quotes, here's what worked for me :

function mytheme_links($links) {
  if (count($links)>0){
    if (isset($links["node_read_more"]) && isset($links["comment_add"])){
      unset($links["comment_add"]);
    }
  }
  return theme_links($links);
}

you obviously need to substitute "mytheme" with your theme name, and clear caches before this works.

It's nice to be important,
but it's more important to be nice.

An addition

If it is desired to also hide the number of comments (that is displayed instead of the comment add link if the node already has comments) ..

<?php
function mytheme_links($links) {
  if (
count($links)>0){
    if (isset(
$links["node_read_more"])){
      if (isset(
$links["comment_add"])) {
        unset(
$links["comment_add"]);
      }
      if (isset(
$links["comment_comments"])) {
        unset(
$links["comment_comments"]);
      }
    }
  }
  return
theme_links($links);
}
?>

this works

You can use hook_link_alter, but you need to add it to a module, not template.php

here's the code:

<?php
/**
* Implementation of hook_link_alter
* Remove add comment link from teaser
**/
function modulename_link_alter(&$links, $node){
  if(
arg(0) == 'node' && is_numeric(arg(1)) ){
    return;
// halt if full page view
 
}elseif( ! empty($links['comment_add']) ){
    unset(
$links['comment_add']);
  }
}
?>

css for removing 'add new comment' link in teasers

I wanted to remove comment_add links from teasers too. And found this fix.

This may be specific to my theme (adapted from pixture_reloaded); but with the right first line, this will work in your style.css.

.node-teaser .actions .comment_add {
display: none;
}

See more in this thread: http://drupal.org/node/133236

Thank you..finally i can

Thank you..finally i can managed to remove 'add new comment"

Sonata
-----------------------------------------------
http://daoes.com
http://tophealthplans.info/artis-indonesia.htm

I had to go all the way down to the element to control that add comment link...Looks like it's working on all browsers too. You'll also have to do it for the comment summary class; comment_comments

ul.links li.comment_add {
display:none;
}

ul.links li.comment_comments {
display:none;
}

I use the D7 Zen theme and

I use the D7 Zen theme and this is what worked for me. This hides the add comment:

.node-teaser .comment-add {
display: none;
}

And, while I was at it, I hid the 'login or register to post comment' in all my teaser nodes using the css below:

.node-teaser .comment_forbidden {
display: none;
}

Reggie W

I agree with akael, comments on teasers do absolutely not make any sense, except in very rare occasions maybe. Shouldn't the comment settings offer this option standard?
Default comment setting:
o Disabled
o Read only
o Read/Write only on node
o Read/Write node & teaser (for those rare occasions...)

Or simply no comments on teasers by default.

I started with Drupal in 2007 and then my life got stuck...

I'm having the same

I'm having the same frustration. Not sure whether to leave it or hack around it, but this really should happen automagically or at least have a configuration somewhere. If "Read more appears", then add "new comment shouldn't".

yeah I agree the "add new

yeah I agree the "add new comment" thing on teasers should be an opt-in feature. An Easy fix is just to install the String Overrides module (http://drupal.org/project/stringoverrides) and replace the string "Add new comment" with nothing. That works nicely and doesn't involve any editing that will disappear with the next update...

Absolutely

I've been using Drupal for quite a while now and I've only just come to adding comments to pages. It's incredible that there's no simple way of removing the "add comment" from teasers. I personally can't think of an example where such behaviour would be desired.

you should just give up on

you should just give up on out of the box solution for drupal as they suck and lack options etc. just use views, panels, display suite and make your way hard to whatever you want, thats drupal way, hard but flexible other way just wont give you results you want.

Can you please somebody help

Can you please somebody help me with removing "add comment" and "taxonomy term" from teaser? I try this code but they don't work for me and my Fusion theme. My site is www.e-oglasi.biz

See my last comment. It's not

See my last comment. It's not pretty but it works.

OK, but how to remove

OK, but how to remove taxonomy terms in bottom of each teaser? And I don't want to add new comment don't show in full node. With String module add new comment is gone on full node.

Module to remove "Add New Comment" link from teasers

Here is a module to remove the "Add New Comment" link from teasers:

Remove "Add New Comment" Link from Teasers

D7 version

Thanks for this module, Jason--I don't know php (yet) and I'm wondering if you have updated this module to D7? I can figure out how to change the .info file by looking at other modules but don't know how to change the function. I'd be very grateful if you could help me. Thank you!

nobody click here