Is there a way to hide or remove the "Add new comment" link? I've searched around and can't seem to find a good solution for this. I've tried adding some PHP code into the template file for my theme, but that didn't work.

Comments

nevets’s picture

If you don't want people to be able to comment you can disable comments for the node type or you can set permissions so they are not allowed.

ace1235’s picture

Thanks for responding. I don't want to disable comments. I just want to remove the link.

shabana.navas’s picture

If you just want to temporarily hide the link, you can just use some basic css. Out of the top of my head, I believe the following bit should get the job done:

li.comment_add {display: none;}

Remember, this will hide it everywhere.

Shabana Navas
snavas@acromedia.com
Software Developer
Acro Media
https://www.acromedia.com
1-800-818-4564
Skype: super.shaba

christopher james francis rodgers’s picture

This is the HTML to be addressed using CSS;
and "li" is not accurate.

<h2 class="comments__form-title">Add new comment</h2>
    <form class="comment-form" action="/zen5/comment/reply/1" method="post" id="comment-form" accept-charset="UTF-8"><div><div id="edit-author--2" class="form-item form-type-item">


All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *

ace1235’s picture

Thanks. Added the code you mentioned to the style sheet but nothing happened. The theme I'm using is Bartik if it matters.

christopher james francis rodgers’s picture

When the "Add new comment" link appears under a summary view of your page,
as you might see on your <front> page (Home page)
as for example when your new content
is promoted to the front page,
it is indeed a "li".

The related HTML in that case is:

<li class="comment-add last"><a href="/zen5/comment/reply/1#comment-form" title="Add a new comment to this page.">Add new comment</a></li>

Please see my other comment below that I will edit to include this case.

Give me a minute and I will try it with Bartik.

Note: I only ever have used FireBug (the awesome FireFox extension) to investigate any page's CSS.


All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *

azafor’s picture

display: none is bad for SEO purpose. Instead i recommend Remove Links From Teaser Module for beginner.

christopher james francis rodgers’s picture

I am curious why you might want to do this,
yet you can achieve this using CSS.

To hide the title "Add new comment",
(h2.comments__form-title)
and the add new comment form,
(form#comment-form)
add the following code to your active theme's CSS:


/**
 * Add New Comment - Hide 
 */

h2.comments__form-title,
form#comment-form {
  display: none;
}


All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *

ace1235’s picture

Tried this but it didn't work. Bartik is the theme I'm using if that matters.

The reason I want to do this is because I already added a link to the comments within the content. I don't need a second link at the bottom of the page.

christopher james francis rodgers’s picture

I think then, all you really need is what @Shabana Blackborder recommended,
except use a dash "-" instead of the underscore "_".

li.comment-add {display: none;}


All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *

ace1235’s picture

Still not working for me.

christopher james francis rodgers’s picture

I am using Dupal 7.23.

===

I assume the comment form is not on your page
because you have unchecked
" Show reply form on the same page as comments ";
for your 'Content type' at:

Structure >> Content types >> click 'edit' for your content type.

[d7-root]/admin/structure/types/manage/**CONTENT_TYPE**

===

Turn off "Aggregate and compress CSS files."

Configuration >> Development: Performance. ...
Heading: Bandwidth optimization

Uncheck: "Aggregate and compress CSS files."

3. Try again.

===

If that does not work,
I would be curious which CSS file you are modifying?


All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *

christopher james francis rodgers’s picture

Note: If you are modifying Bartik,
it is recommended that you first create a subtheme.
See the heading "Creating a subtheme" on the page
"How to Customize Bartik" - https://drupal.org/node/1114190


All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *

ace1235’s picture

I'm making my edits using a sub theme for Bartik. The file I'm adding the code to is "style.css" in the "css" folder. "Aggregate and uncheck css" files is unchecked. I have "Show reply form on the same page as comments" checked because I am using the Talk module to display comments + comment form on a separate tab. So, I want them to display on the same page. To test if this is why the additional css code wasn't working I went ahead and unchecked "Show reply form on the same page as comments". The additional css still didn't remove the "Add new comment" link after doing so.

I am theming the site locally if it matters.

Also, I have display suite installed. I don't know if this affects anything or not.

jbd44’s picture

This is how Bartik's node.tpl.php solves the problem.

<?php
  // Remove the "Add new comment" link on the teaser page or if the comment
  // form is being displayed on the same page.
  if ($teaser || !empty($content['comments']['comment_form'])) {
    unset($content['links']['comment']['#links']['comment-add']);
  }
  // Only display the wrapper div if there are links.
  $links = render($content['links']);
  if ($links):
?>
  <div class="link-wrapper">
    <?php print $links; ?>
  </div>
<?php endif; ?>

Replace this line (below) in the standard D7 node.tpl.php with the above, then put it in your theme's templates folder:

<?php print render($content['links']); ?>

Lady3mlnm’s picture

I had similar task on Drupal 8.3. To remove "Add new comment" & "Log in to post comments" from views of teasers but remain them in articles itself. Standard theme "Bartic".

I used module CSS Editor and fit into the theme CSS

div.views-row li.comment-add, div.views-row li.comment-forbidden
  {display: none;}

Everithing is working.

DRPISC’s picture

Disabling Links field under Manage display tab removes the Add new comment link.

liam morland’s picture

The "Log in or register to post comments" link only appears if the "Authenticated" role has permission post comments; see CommentManager::forbiddenMessage().