How to use hook_form_alter in the .theme file to alter the form fields? I need to know how to use hook_form_alter in .theme file as i have to alter the form fields related to user_register_form.

I tried putting the below code in the .theme file but it does not even reach the function

/**
 * Implements hook_form_alter().
 */
function hook_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Adding custom validation for the welcome page type field.
  if ($form_id == 'user_register_form') {
     print_r('Reaching in here');exit;
  }
}
If you want to alter a specific form, and you know the ID, use hook_form_FORM_ID_alter() rather than the generic version:

function THEMENAME_form_user_register_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  // Add alterations specific to the user registration form
}


Make sure you clear the cache after renaming the function.