Redirect users to a custom URL from the 2FA wizard

You are here:
  • Home
  • WP 2FA
  • Redirect users to a custom URL from the 2FA wizard

By default, when users exit the 2FA setup wizard they are redirected their profile page. This happens regardless if they complete the wizard of if they click the “close wizard” link prior to finishing the setup.

This redirect is possible because we use the get_edit_profile_url, a WordPress core function. This means that if you would like to instead redirect your users to other URLs you can easily to so.

Here is an example how you can do this. Add the below code inside your functions.php file or website plugin:

add_filter( 'edit_profile_url', 'my_custom_profile_url', 10, 3 );
function my_custom_profile_url( $url, $user_id, $scheme ) {
$url = 'http://example.com/a-page';
return $url;
}

All you need to do is edit the $url to reflect the URL you wish to redirect the users to. Should you wan, you can also apply any other logic (such as a specific URLs based on role etc) here too.