Web Development & WordPress

Based on User Role ( subscriber , editor) redirect to different url or login page During Logout action

If you want your Client ( user role created) or Editors to be redirected to different urls while they logout, use the code i shared below. Just change the urls in the code and paste it in your child theme’s function.php or use Code Snippet Plugins.

function custom_logout_redirect() {
    
    $current_user = wp_get_current_user();
    
    if (in_array('client', $current_user->roles)) {
       wp_redirect('https://example.com/client-login/');
        exit();
    }

    if (in_array('editor', $current_user->roles)) {
        wp_redirect('https://example.com/coachs-login/');
        exit();
    }
}

add_action('clear_auth_cookie', 'custom_logout_redirect', 10, 0);

Leave a comment