• Resolved shivks

    (@shivks)


    Most of the pages on our site are visible to logged-in-users only. Our site is pretty massive, multi-site, so users will send each other deep links in e.g. email, and users like to bookmark deep links. (So https://site.com/blogname/some/specific/post or https://site.com/blogname/somepage .) However, on login, users are redirected to blogname/wp-admin, not the page they originally requested. I’ve found ways to redirect them to some other generic page, but no way to redirect them to their originally requested page.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi shivks.
    try this code. i hope you can get an idea and modify this according to your needs.

    add_filter('login_redirect', 'redirect_previous_page', 10);
    
    function redirect_previous_page(){
        global $user;
        $request = $_SERVER["HTTP_REFERER"];
        if ( in_array( $user->roles[0], array( 'administrator') ) ) {
            return admin_url();
            return $redirect_to;
        } elseif ( in_array( $user->roles[0], array( 'subscriber') ) ) {
            return $request;
            return $redirect_to;
        }
    }

    Hi Maavuz,

    Thanks for this code.
    I’m in the same situation as Shivks and this will be a great help.

    Just one question; Should I add this to functions.php or somewhere else as I’m worried about it getting overwritten by an update in WP or my theme.

    Thanks,
    Donal

    Hi donal.long.
    Add this code in your themes function.php

    Thread Starter shivks

    (@shivks)

    Issue Solved.

    I am using cookie to store requested url and pass it to through wp-redirect.

    Hi Shivks

    Can you provide some more details about how you are using a cookie to redirect?

    Thanks again,
    Donal

    Thread Starter shivks

    (@shivks)

    Hi donal,

    $cookie_name = “1”;
    $cookie_value = $_SERVER[‘REQUEST_URI’];//it will get requested url
    setcookie($cookie_name, $cookie_value, 0, “/”);//once browser closed cookie //will delete

    Place this above code in main index.php file.

    and in wp-login.php file , to use that cookie to redirect it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘redirect to original url request after login – possible?’ is closed to new replies.