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

tdailey’s picture

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.

akael’s picture

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.

suffering drupal’s picture

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...

VSZ’s picture

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.

tallsimon’s picture

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

Maine’s picture

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

hexblot’s picture

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.

mahmost’s picture

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) ..

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);
}
silypointer’s picture

It Worked out!
just $links["comment_add"] should be $links["comment-add"] adn the other field in array too.
Rest everything fine.
Thanks

davidwhthomas’s picture

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']);
  }
}
?>
eff_shaped’s picture

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

daoes_2000’s picture

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

g35nightrider’s picture

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;
}

rwilson0429’s picture

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;
}

ReggieW

suffering drupal’s picture

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...

lhtown’s picture

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".

armanschwarz’s picture

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...

RichieRich’s picture

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.

Marko B’s picture

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.

doktorrr’s picture

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

armanschwarz’s picture

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

doktorrr’s picture

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.

udinaja’s picture

me also asking the same thing.

Honda Balikpapan

armanschwarz’s picture

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

Remove "Add New Comment" Link from Teasers

cartagena’s picture

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!

Web Building and Design

chaiwei’s picture

D7.. I am using hook_node_view_alter to remove the links


function YOURMODULE_node_view_alter(&$build){  
    
    if($build['#view_mode'] == 'teaser' && $build['#bundle'] == 'product'){

      // Remove "Add new comment" link
      unset($build['links']['comment']['#links']['comment-add']);

      // Remove "Read more" link
      unset($build['links']['node']['#links']['node-readmore']);

      // Remove "1 comment" link
      unset($build['links']['comment']['#links']['comment-comments']);
    } 
}
ClariceGChen’s picture

I wanted to remove comment_add links from teasers too. And found this fix.
http://nissinfoods.com.vn/tags/cach-cham-soc-da-mat

rwilson0429’s picture

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

ReggieW

silypointer’s picture

Hey,

CSS can do your work, but it is not advisable every time to use css for such issues.