Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi @alanp57,

    Apologies for getting back to you late.
    Regarding your query, I am slightly confused. Do you mean that you want to redirect users to the same page after they hit the login button?
    Please correct me if I am wrong and let me know your query in a bit detail so that it would be easy for me to assist you.

    Regards!

    Thread Starter AlanP57

    (@alanp57)

    Users need to go back to the previous web page they were on when they clicked the link to register or login.

    Hi @alanp57,

    Apologies for the delayed response.
    You can redirect your users to a specific page by using a redirect URL parameter in my account shortcode. You can use it like this: [user_registration_my_account redirect_url=”sample-page”] in your account page.
    Make sure that you change the “sample-page” with the slug of the page where you want your users to redirect.

    Let me know if it helps or not and I will get back to you.

    Regards!

    Thread Starter AlanP57

    (@alanp57)

    It needs to redirect the user to the page he came from, which is know as the referer. Another user at this thread said adding some hook functions will make it do that. These are the hook functions:

    add_action( 'user_registration_before_customer_login_form', 'ur_set_redirect_url' );
    function ur_set_redirect_url() {
        if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
        set_transient( 'originalLoginRefererURL', $_SERVER['HTTP_REFERER'], 60*60*24 );
    }
    
    }
    
    add_filter( 'user_registration_login_redirect', 'ur_redirect_back', 10, 2 );
    function ur_redirect_back( $redirect, $user ) {
        if ( true === ( $redirect_url = get_transient( 'originalLoginRefererURL' ) ) ) {
            delete_transient( 'originalLoginRefererURL' );
            return $redirect_url;
        }
        return $redirect_url;
    }

    I would appreciate if there is a way to get this code to work.

    Hi @alanp57,

    Apologies for my understanding.
    Please copy and paste the following code and let be know if it works or not.

    add_action( 'user_registration_before_customer_login_form', 'ur_set_login_redirect_url' );
    function ur_set_login_redirect_url() {
        if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
            set_transient( 'originalLoginRefererURL', $_SERVER['HTTP_REFERER'], 60*60*24 );
        }
    }
    add_filter( 'user_registration_login_redirect', 'ur_login_redirect_back', 10, 2 );
    function ur_login_redirect_back( $redirect, $user ) {
        if ( true === ( $redirect_url = get_transient( 'originalLoginRefererURL' ) ) ) {
            delete_transient( 'originalLoginRefererURL' );
            return $redirect_url;
        }
        return $redirect_url;
    }
    add_action( 'user_registration_before_registration_form', 'ur_set_register_redirect_url' );
    function ur_set_register_redirect_url( $form_id )
    {
        if (isset($_SERVER['HTTP_REFERER'])) {
            set_transient('originalLoginRefererURL', $_SERVER['HTTP_REFERER'], 60 * 60 * 24);
        }
    }
    add_filter( 'user_registration_redirect_from_registration_page', 'ur_register_redirect_back', 10, 2 );
    function ur_register_redirect_back( $redirect, $user ) {
        if ( true === ( $redirect_url = get_transient( 'originalLoginRefererURL' ) ) ) {
            delete_transient( 'originalLoginRefererURL' );
            return $redirect_url;
        }
        return $redirect_url;
    }

    I hope this helps.

    Regards!

    Thread Starter AlanP57

    (@alanp57)

    Yes, it works. Thank you very much!

    Thread Starter AlanP57

    (@alanp57)

    A similar follow up question, how can I have users redirected to the referer page when they when they click a link to log in, which takes them to the my account page?

    Hi @alanp57,

    Could you please elaborate in a bit more detail so that I can understand what exactly are you looking to achieve? It seems a bit confusing as I am finding it a bit difficult to point out the difference between your previous query and this one.

    Please let me know and I will get back to you.

    Regards!

    Thread Starter AlanP57

    (@alanp57)

    The previous question had to do with redirecting from the registration page, the page that contains the [user_registration_form] short code (the registration form). For users who are already registered, there is the My Account page which contains the [user_registration_my_account] short code (the log in form). When user who are already registered are sent to the My Account page, they should be redirected to the referer link on successful login.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Not redirecting’ is closed to new replies.