Comments Approach

By default, at the end of an article Drupal displays the text "Login to post comments". To remove this text, allow commenting for anonymous users or just disable the Comment module.

Settings Override

You can use custom strings by adding something like this to /sites/default/settings.php:

$conf['locale_custom_strings_en'] = array(
'Add new comment' => 'Discuss',
'<a href="@login">Login</a> to post comments' => '',
);

Anonymous User Override

If you want to keep the ability to comment for logged-in users only, and remove the "login to post comments" text for anonymous users, you can add the following snippet to the end of your template.php file in your Theme folder. Remember to flush caches after updating the template.php file..

function phptemplate_links($links, $attributes = array()) {
  global $user;
  if (!$user->uid) {
    unset($links['comment_forbidden']);
  }
  return theme_links($links, $attributes);
}

for more info see: http://drupal.org/node/425332

Remove link from teasers only

You can remove the links from teasers only enabling the following custom mini module

<?php
function MODULE_NAME_link_alter(&$links, $node) {
if (arg(0) == "node" && is_numeric(arg(1)) && arg(2) == NULL) {
  }
  else {
  foreach ($links AS $module => $link) {
    if (strcmp('comment_forbidden', $module) == 0) {
      unset($links[$module]);
    }
  }
}
}
?>

Remove from comments only

if you just want to remove the 'login to post comments' from the bottom of comments, but not from the node links your mini module would have to look like this :

function MODULE_NAME_link_alter(&$links, $node, $comment = NULL){
    if($comment){
        unset($links['comment_forbidden']);
    }
}

if you want to remove it everywhere, remove the if statement.

Remove links in Drupal 7 sites

In Drupal 7, you no longer need a comment-specific option. In a custom module, call hook_node_view to change the node before it is displayed.

For example, to remove the 'login or register to post comments' link:


function MYMODULE_node_view($node, $view_mode) {
  // Use these statements with the devel module enabled
  // to find out more information about the node and 
  // view mode to be altered.
  dpm($view_mode);
  dpm($node);
  // For anonymous users, use a watchdog statement.
  watchdog('fix', '<pre>'.print_r($node->content['links']['comment']['#links']['comment_forbidden'], TRUE).'</pre>');
  // Tell it which view_mode to change, 'full', 'teaser', etc.
  if ($view_mode == 'full') {
    // Take out the link by unsetting it.
    unset($node->content['links']['comment']['#links']['comment_forbidden']);
  }
}

Credits:
http://11heavens.com/Drupal-coder-lost-in-space/where-are-we
http://drupal.org/node/170065#comment-855410

Comments

cajmcmahon’s picture

Does anyone know how to get rid of the "Log in or register to post comments" that appear between/after every single comment?

The D7 module example ("Remove links in Drupal 7 sites") above does indeed remove of the main "Log in or register to post comments" link which is good, but I've still got a proliferation of these mini links.

As far as I can tell, the array is:
['comments']['comments']['links']['comment']['#links']['comment_forbidden']

Thus in a custom module:

function customsite_node_view($node, $view_mode) {
    unset($node->content['comments']['comments']['links']['comment']['#links']['comment_forbidden']);
}

Unfortunately, I haven't got it work yet so if anyone can offer a suggestion...

cajmcmahon’s picture

Got it... after several days of trying... (urghh!)

This is for D7, custom module.

Nothing I tried using hook_node_view would alter the properties of the Comment section so I started looking through the API documentation. I found there is an equivalent hook for Comments: hook_comment_view (http://api.drupal.org/api/drupal/modules--comment--comment.api.php/funct...)

At the same time I was looking (again) through comment.module (drupal/modules/comment/comment.module) for mentions of 'comment_forbidden'. Around line 670 I found ($node->comment.... This provided me with the syntax I needed to change properties within the Comment section.

First I tried this, which removed all links, e.g. "Delete", "Edit". I didn't want this as I need the Admin to be able to edit individual comments (for abuse, etc.):

function customsite_comment_view($comment, $view_mode, $langcode) {
    unset($comment->content['links']);
}

Then I refined it using the example from above, getting rid of just 'comment_forbidden' (the same nested array worked)

function customsite_comment_view($comment, $view_mode, $langcode) {
    unset($comment->content['links']['comment']['#links']['comment_forbidden']);
}

I didn't add back in the "watchdog" function for anonymous users as I didn't need it.

I did put in the statement for this to only operate on "full" nodes views, producing this final, complete and functioning version:

function customsite_comment_view($comment, $view_mode, $langcode) {
// Tell it which view_mode to change, 'full', 'teaser', etc.
  if ($view_mode == 'full') {
// Take out the link by unsetting it.
    unset($comment->content['links']['comment']['#links']['comment_forbidden']);
}
}

As always, if anyone's got any improvements, I'm all ears...

ardbegdrup’s picture

Is it possible to get in module form? Just like in D6 http://drupal.org/project/RemoveAddNewCommentTeaserLink

jaap76’s picture

+1

jaap76’s picture

function phptemplate_links($links, $attributes = array()) {
  global $user;
  if (!$user->uid) {
    unset($links['comment_forbidden']);
  }
  return theme_links($links, $attributes);
}

This code works for me. Thank you.

Now I wonder, is there a same sort of snippet that makes it possible to only show 'login to reply' on full nodes?

jaap76’s picture

I'm a step further.

On the node.tpl.php in my custom theme folder I added this code

<?php if ($links && !$teaser): ?>
/* theme divs in between */
<?php print $links; ?>
<?php endif; ?>

Now the login/ register line is away from the teasers, while it shows on full nodes. The final bit to make me happy is removing the login/ register link from the comments. Right now it's showing on every comment reply.

This is my line on my custom comment.tpl.php file

<div class="links"><?php echo $links; ?><div class="cleared"></div></div>

I can remove this line, but than logical all links are gone. I want to keep the 'edit' 'reply' and 'delete' links when people are signed on. How to do that? On Drupal almost all codes are written to remove it from the teasers, but the comment module/ comment.tpl.php file.

jaap76’s picture

I tried to create the mini module with some coding from up here in this topic, but I get a white page with a text line: function loginremove_link_alter(&$links, $node, $comment = NULL){ if($comment){ unset($links['comment_forbidden']); } }

In sites/default/modules/ I created a folder 'loginremove'

In this folder I have 2 files. loginremove.info and loginremove.module

This are the codes:

loginremove.info:

; $Id: loginremove.info,v 1.0.0.0 2011/10/10 10:10:10 setfree Exp $
name = Remove Login from Comments
description = This will remove the login/ register link from the comment module.
core = 6.x
version = "6.x-1.0"
core = "6.x"
project = "loginremove"
datestamp = "20111010"

loginremove.module

function loginremove_link_alter(&$links, $node, $comment = NULL){
    if($comment){
        unset($links['comment_forbidden']);
    }
}

Whats wrong?

jaap76’s picture

It works in D6

I hope this useful to others facing the same problem.

1) Create in nodepad, or you favorite text editor a blank file.

Copy Paste this code:

; $Id$
name = Comment login link removal
description = Removes the "login/register" link on comments.
version = "6.x-1.0"
core = "6.x"

Call this file remove_login_comment.info

Than open a second blank file and copy/paste this code:

<?php
// $Id$

/**
 * @file
 * Removes the "login/register" link from comments.
 *
 */

//invoke the link_alter hook
function remove_login_comment_link_alter(&$links, $node, $comment = NULL){
    if($comment){
        unset($links['comment_forbidden']);
    }
}
?>

Call this file remove_login_comment.module

Than create a new folder and name it remove_login_comment and add the 2 files in this folder. Than add the folder into your /sites/default/modules (or /sites/all/modules) folder and use the admin panel/ modules to install your mini module.

The 'edit' 'delete' 'reply' link will stay for logged on users.

sano’s picture

Does the module not need to have .install file? I followed the instructions given, but the new module is not appearing in the list of modules on the admin/build/modules page

ericprado’s picture

It worked on my site. Thanks. Now I can disable anynonymous from commenting on my site, which is always flooded with comments. I can see log-in/register on every comment. :) So great!