Skip to main content
comment

Removing "Login or register to post comments" link from comment view

Drupal provides a handful of settings to format the comment listing. One thing that we found very irrelevant in comment view is the link item "Login or register to post comments" especially when the comments are styled to display as flat items. Let's take the snapshot below from drupal.org issue queue.


[[{"type":"media","view_mode":"media_original","fid":"102","attributes":{"alt":"","class":"media-image","typeof":"foaf:Image"}}]]

It is obvious that login and register link in every comment is not needed. Fortunately Drupal 7 provides a hook to alter comment view output hook_comment_view_alter(&$build)

  1. /**
  2.  * Implementation of hook_comment_view_alter().
  3.  */
  4. function kf_module_comment_view_alter(&$build) {
  5.   if (($build['#node']->type == 'blog') && isset($build['links']['comment']['#links']['comment_forbidden'])) {
  6.     unset($build['links']['comment']['#links']['comment_forbidden']);
  7.   }
  8. }

This five lines of code shared above does the trick of removing unwanted stuff from comment view.

Comments