How can I prevent "Log in to post comments" from displaying for anonymous users? How do I remove the &quot;Log in to post comments&quot; from the bottom of my content in Drupal 8 while keeping old comments visible to all and allowing existing registered users to still comment? Basically, I don't want anonymous users to find my login page, ever. These means no CSS hide or Javascript solutions (bots will still follow the link).
So, if comments exist on a node:
I want anonymous users to:

See the comments as usual
NOT see any sort of &quot;add comment&quot; link
NOT see any sort of &quot;login/register&quot; link either

I want authenticated users to:

See the comments as usual
See &quot;add/reply&quot; comment links as usual

If comments DO NOT exist on a node:
I want anonymous users to:

See NOTHING at the bottom of the node

I want authenticated users to:

See &quot;add comment&quot; link as usual
You can do it using hook_preprocess_HOOK
The following hooks should be placed in YOURTHEME.theme file:


Remove comment links from node for Anonymous user:




    /**
     * Implements hook_preprocess_HOOK().
     */
    function YOURTHEME_preprocess_links__node(&$variables) {
      if (\Drupal::currentUser()->isAnonymous()) {
        unset($variables['links']['comment-forbidden']);
      }
    }




Remove links from the comments for Anonymous user:




/**
 * Implements hook_preprocess_HOOK().
 */
function YOURTHEME_preprocess_links__comment(&$variables) {
  if (\Drupal::currentUser()->isAnonymous()) {
    unset($variables['links']['comment-forbidden']);
  }
}