A member on your site is reading a post with protected content. This can be either fully protected so they see a prompt to login or partially protected so they see some teaser content with a prompt. In order to see the full content, they must login. After clicking the login link, they end up on the Login page. By default, after logging in, that member is immediately directed to the "Home Page" you have defined in the Member Homepage Settings. The following article outlines how you can change this behavior and instead direct the member back to the post they were just reading.


Option 1: Use a Hidden HTML Field


You can use a similar approach to the example that a User on StackExchange posted as their solution. The following code will grab the URI the user was on before they attempted to login, no matter the string parameters, then redirect them back to that same page after a successful login. Simply include the highlighted code below on your login page in-between the [MM_Form type='login'][/MM_Form] like shown in the example:


[MM_Form type='login']

...

<input type="hidden" name="redirect_to" value="?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];?">

...

[/MM_Form]



PLEASE NOTE: Though MemberMouse is sharing this 3rd party approach, we can not support this solution if you should run into any issues trying to use this script. This is a solution provided to you purely out of one of our support team's personal experience and any unexpected situations you may encounter trying to use this script will be outside of our support policy.



Option 2: Use a Custom PHP Script


If the above solution does not work for your situation, a MemberMouse user named Thiago, has shared his resolution to this situation and has given us permission to share it with other members. Using the following code with edits as needed, and whatever approach you like to add php to your site, you can accomplish the same redirect functionality, with a few extra benefits. This code also stores a cookie and links directly to page ID's. 

// Redirect after login


function frc_login_redirect() {


    $frc_page = 'frc_page';




    // 16503 = "Login" page


    // 16500 = "Member Home" page




    // set cookie


    if (!is_user_logged_in() && !is_page(16503) && !is_page(16500) ) {


        $post_id = get_the_id();


        setcookie($frc_page, $post_id, time() + 60 * 60, '/');

    }




    // redirect after login


    if (is_user_logged_in() && is_page(16500) && isset($_COOKIE[$frc_page])) {


        // get url to redirect


        $redirect_url = get_permalink($_COOKIE[$frc_page]);




        // delete cookie


        unset($_COOKIE[$frc_page]);


        setcookie($frc_page, null, time() - 3600, '/');




        // redirect


        wp_safe_redirect($redirect_url, 307); // 307 Temporary Redirect


        exit();

    }

}


add_action('template_redirect', 'frc_login_redirect'); 


PLEASE NOTE: Though MemberMouse is sharing this 3rd party approach, this is not a solution that we can support. This is a solution provided to you purely out of one of our customer's personal experience and we can not support any issues you may encounter trying to use this script if it does not function as expected on your site.