0

I'm using "Passwordless Login with OTP / SMS & Email - Facebook Account Kit" for login.

I want to redirect user to http://www.domain.com/author/<username>/screen after they log in

this is the code I used

$current_user = wp_get_current_user();
if ( is_user_logged_in() ) {
    $redirect = ('http://www.domain.com/author/'.$current_user->user_login.'/screen'); }

It redirect to http://www.domain.com/author/screen without the username. can anyone help me with this

2 Answers 2

0
function login_redirect( $redirect_to, $request, $user ){
    $URL ="http://www.abcgg.com";
    return $URL;
}
add_filter( 'login_redirect', 'login_redirect', 10, 3 );
0

The problem is that wp_get_current_user() is not available until after pluggable is run. Try adding your code to a later hook:

add_action( 'wp_login', function () {
    $current_user = wp_get_current_user();
    if ( is_user_logged_in() ) {
        $redirect = ('http://www.domain.com/author/'.$current_user->user_login.'/screen'); 
    }
});
2
  • thank you for the answer I tried with this code but now it redirects to "domain.com/wp-admin Commented Jul 23, 2019 at 13:06
  • try adding wp_die($redirect); to help debug what may be the issue Commented Jul 23, 2019 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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