Authentication Forms: change the links below the forms

You may want to change the registration, login or forgot password links that can be seen below the form. This can be done using hooks in your theme’s functions.php file.

The simple way

If you just need to change the URL of the link, you can simply use a hook like this:

function cuar_change_login_link($original_url, $redirect_to) {
  return 'http://example.com/my-custom-login-page';
}
add_filter('cuar/authentication-forms/form-url?action=login', 'cuar_change_login_link', 10, 2);

function cuar_change_register_link($original_url) {
  return 'http://example.com/my-custom-register-page';
}
add_filter('cuar/authentication-forms/form-url?action=register', 'cuar_change_login_link', 10, 2);

// And so on with other hooks:
// 'cuar/authentication-forms/form-url?action=forgot-password'
// 'cuar/authentication-forms/form-url?action=reset-password'
// 'cuar/authentication-forms/form-url?action=logout'

A more advanced solution

If you need more flexibility – to change the texts, add more links, etc. – you can use the snippet below:

function cuar_change_auth_links($links, $current_form_id) {
  // Here is how we could change the target of the register link
  if (isset($links['register'])) {
    $links['register'] = sprintf( '%2$s',
      esc_attr('http://example.com/my-custom-registration-form'), 
      esc_html(__('Create your account', 'cuarlf'))
    );
  }

  // Here is how we could remove the forgot password link
  unset($links['forgot-password']);

  // Here is how we can add a custom link
  $links['tos'] = sprintf( '%2$s',
    esc_attr('http://example.com/terms-of-service'), 
    esc_html(__('Terms of service', 'yourdomain'))
  );

  return $links;
}
add_filter('cuar/authentication-forms/form-links', 'cuar_change_auth_links', 10, 2);

In this case, it is always a good idea to also use the simple snippets to update the URLs too.