简体   繁体   中英

redirect to specific page after login based on browser language

in my functions.php i have a redirect after login. currently this:

add_action( 'template_redirect', 'wpdm_login_redirect' );
function wpdm_login_redirect(){
if( is_user_logged_in() && get_the_ID() == get_option('__wpdm_login_url') ):
    wp_redirect( home_url('/dashboard') );
    exit();
endif;
}

this works as expected, but i need to combine it with a redirect to a different page if the browser language is detected as italian, so an if ($lang=="it_IT") redirect to home_url('/area_personale'), and everyone else to '/dashboard'

i'm very new at this, so my problem is how to get this language stuff into my existing login redirect. or maybe there is an 'easier' way to go about this? any guidance most appreciated!

This should do the trick.

add_action( 'template_redirect', 'wpdm_login_redirect' );
function wpdm_login_redirect(){
$language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);

if( is_user_logged_in() && get_the_ID() == get_option('__wpdm_login_url') && $language == "it_IT" ):
    wp_redirect( home_url('/area_personale') );
    exit();

    else:

        wp_redirect( home_url('/dashboard') );

endif;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM