• Hello,
    When I log in to site https://www.trustchem.eu/beheer/ I want to redirect to home page
    For this I used this code

    function login_redirect() {
        $redirect_url = $_SERVER['HTTP_REFERER'];
        $redirect_url = str_replace("/beheer","",$redirect_url);
        wp_redirect($redirect_url);
    }
    add_action('wp_login', 'login_redirect');

    All working for administrator user. But when login as contributor instead of home page WP redirects to profile page
    https://www.trustchem.eu/wp-admin/profile.php

    Not clear why this happens. Can somebody help me to figure out what is problem ?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try this instead:

    add_action('wp_login','auto_redirect_after_login');
    function auto_redirect_after_login(){
    wp_redirect( home_url() );
    }

    Hope this helps. Once you find a solution please tag the thread as resolved.

    • This reply was modified 5 years, 7 months ago by Davood Denavi.
    Thread Starter volodika

    (@volodika)

    This code not helped. User redirected to their profile

    add_action('wp_login','auto_redirect_after_login');

    Please try moving that to the bottom… like this

    function auto_redirect_after_login(){
    wp_redirect( home_url() );
    }
    add_action('wp_login','auto_redirect_after_login');

    It likely wont make a difference but sometimes it does for me.

    I’ve just create a new WP with different roles:
    Editors – 1 user called editor01
    Sales – 1 user called sale01

    (in future multiple users for thes roles)…

    I must redirect after login page to specific homepage conditionned by role… I write the following code:

    ————-SOURCE CODE HERE—————
    add_action(‘wp_logout’,’auto_redirect_after_logout’);
    function auto_redirect_after_logout(){
    wp_redirect( home_url() );
    exit();
    }

    add_action(‘wp_login’,’login_redirect’);
    function login_redirect() {
    $user = wp_get_current_user();
    $roles = $user->roles;
    if (isset($roles) && is_array($roles)) {
    if (in_array(‘administrator’, $roles)) {
    // redirect them to the default place
    wp_redirect(home_url() . ‘/wp-admin/’);
    exit();
    }
    if (in_array(‘Sales’, $roles, true)) {
    wp_redirect(home_url() . ‘/wepos/#/’);
    exit();
    }
    // ….. for other roles if then ….
    } else {
    wp_redirect(home_url() . ‘/wepos/#/’);
    exit();
    }
    }
    ————-SOURCE CODE END—————
    Redirect doesnt work and return to original page of user informations

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Redirect After Login Problem’ is closed to new replies.