Remove/hide "Add New Comment" link for authorized users on full nodes

Created on 23 August 2011, over 13 years ago
Updated 30 December 2024, 9 days ago

Remove/hide "Add New Comment" link for authorized / logged in / authenticated / registered users on Drupal 7 pages (full nodes).

I'm attempting to theme / style the node $links. This is apparently notoriously difficult to do. Even splitting up the $links elements is tough. It's pretty much an all-or-nothing situation. Anyway...

I moved the "new comment" textbox right up under the page content (above the comments) (see screenshot). This makes the "Add New Comment" link redundant for logged-in users because the textbox is right underneath it (instead of being way at the bottom of the page out of sight). Anonymous users should still see the "Log in or register to post comments" link.

I've played around with custom modules and template overrides but then I thought it could be as simple as something like below...

In node-tpl.php...

global $user;
if ($user->uid) {
		hide($content['links']['#links']['comment_add']);
}

Or something like (also in node-tpl.php)...

<?php
      // We hide the comments and links now so that we can render them later.
      hide($content['comments']);
      hide($content['links']);
      hide($content['links']['#links']['comment_add']);
    ?>
  </div>
  <?php print render($content['links']['#links']['comment_add']); ?>
  <?php print render($content['links']['#links']['statistics_counter']); ?>
  <?php print render($content['comments']); ?>
  ?>

So far I haven't been able to get anything to work.
Any help or suggestions would be much appreciated...

💬 Support request
Status

Fixed

Version

11.1 🔥

Component

node system

Created by

🇮🇪Ireland cajmcmahon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024