Drupal 8 How to remove Log in and Reset your password local tasks from login form

Profile picture for user a.berramou
Azz-eddine BERRAMOU 27 January, 2020

How to remove Log in ,Create new account and Reset your password  local tasks in login form.
local tasks login form

You can remove Create new account local task by allow only Administrators to create accounts, so just go to Configuration > Account settings > REGISTRATION AND CANCELLATION  and check Administrators only like this:

settings config

But the other two local tasks Log in and Reset your password there is no way to hide or remove them from the UI, the only way is to use hook_menu_local_tasks_alter :

<?php

/**
 * Implements hook_menu_local_tasks_alter().
 */
function YOURMODULE_menu_local_tasks_alter(&$data, $route_name) {
  if($route_name == 'user.login'  && isset($data['tabs'][0])) {
    // Remove all tabs from user login form.
    foreach ($data['tabs'][0] as $key => $tab){
      $data['tabs'][0][$key]['#access'] = FALSE;
    }
  }
}

Clear cache and you are done!