1

I would like to indicate that if you do not have the first_name filled in when logging in, you will be redirected to a specific page, for example /onboarding and if the first_name field is filled, you would be redirected to the home page. I would like it to always perform the check and redirect whenever first_name is empty

I am trying the following code but it does not work.

function login_redirect( $redirect, $user ) {    
// Get user meta
$field_empty = get_user_meta( $user->ID, 'first_name', true );

// Empty
if ( empty( $field_empty ) ) {
    $redirect = '/onboarding';
} else {
 
    $redirect = '/';     
}

return $redirect;
}
3
  • 1
    are you binding this function with some hook? if so can you share that part of the code?
    – MMK
    Commented Mar 9, 2022 at 8:57
  • This is the complete code. function onboarding_redireccion( $redirect, $user ) { // Get user meta $value = get_user_meta( $user->ID, 'first_name', true ); // Empty if ( empty( $value ) ) { $redirect = '/onboarding'; } else { // Get the "home_url" url $redirect = '/'; } return $redirect; } add_filter( 'login_redirect', 'onboarding_redireccion', 10, 3 ); The problem with this is that, even though I have first_name with content, the code keeps redirecting me to /onboarding Commented Mar 11, 2022 at 20:02

0

Your Answer

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

Browse other questions tagged or ask your own question.