I want to remove the following default links on the login block.

  • Create new account
  • Reset your password

I used hook_form_alter() but there is nothing in there that creates these links.


Method #1

Implement hook_preprocess_block() in your module/theme.

 * Implements hook_preprocess_HOOK().
function HOOK_preprocess_block__user_login_block(&$variables) {
  $variables['content']['user_links']['#access'] = FALSE;

Method #2

Override block--user-login-block.html.twig template and replace {{ content }} with the following {{ content|without('user_links') }}.

Note that hiding those links would not protect respective pages (user/register and user/password) from direct access.


It's better to set proper permissions, because removing the links won't prevent users from typing user/register and user/password in the browser's address bar and reaching them directly.

However, if you really want to remove those links from the login block using the hook, then the following code should work:

function hook_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'user_login_block') {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.