• Resolved johnping

    (@johnping)


    Hello,
    I need to redirect user to the previous/last page after he login or registration. I set automatically login after registration and no need approval.
    Could you please kindly help with a snippet or any setting figuration?

    Thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter johnping

    (@johnping)

    Hi team,

    Any updates on my topic?

    Plugin Support sanjuacharya77

    (@sanjuacharya77)

    Hi @johnping,

    Thanks for writing in.

    Could you please add the given code to your current theme functions.php file to redirect back to the previous page after registration?

    Here is the code

    add_action( 'user_registration_before_registration_form', 'ur_set_redirect_after_register', 10, 1 );
    function ur_set_redirect_after_register( $form_id ) {
        if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
            set_transient( 'originalRegisterRefererURL', $_SERVER['HTTP_REFERER'], 60 * 60 * 24 );
        }
    }
    add_action( 'user_registration_redirect_from_registration_page', 'redirect_back_after_registration', 10, 2 );
    function redirect_back_after_registration( $redirect_url, $user ) {
        $redirect = get_transient( 'originalRegisterRefererURL' );
        delete_transient( 'originalRegisterRefererURL' );
        return $redirect;
    }

    Let us know whether it works for you or not and I will get back to you.

    Regards!

    Thread Starter johnping

    (@johnping)

    Hi sanjuacharya,

    Thanks a lot for the snippet. However, It doesn’t work. I use Avada Theme, and added it into Avada Child theme’s functions.php file. I put nothing in Redirect URL on form setting, so it still stays on the login/register page after user login/register.

    Could you please help? Thank you.

    • This reply was modified 2 years, 5 months ago by johnping.
    Thread Starter johnping

    (@johnping)

    Hi Team,

    I’m still waiting for your reply.

    Thank you.

    Plugin Support sanjuacharya77

    (@sanjuacharya77)

    Hi @johnping,

    It is working on our site, here is the screen-recording of my test: https://encl.io/t/KurkX-IHB0s#P9LEBRUX4FnpA-djUL806A. Once could you please try switching to the WordPress default theme and see if it works or not?

    Also, Could you Please provide us with the URL of the registration form?

    Regards!

    Thread Starter johnping

    (@johnping)

    Hi @sanjuacharya77

    Really appreciate your demo and patience. It might conflict with my theme.
    I found another way to make it by adding a js snippet at footer page as follows:

    <script>
    jQuery(document).ready(function($){
    var lailu=document.referrer;
    console.log(lailu);
    $("input[name='redirect']").val(lailu);
    $("input[name='ur-redirect-url']").val(lailu);
    });
      </script>

    I don’t know whether it works for other themes, but current works fine on my site. Just paste it here for others who may need it.

    Thank you again. UR is really a great plugin, and you guys are very nice.

    • This reply was modified 2 years, 4 months ago by johnping.
    • This reply was modified 2 years, 4 months ago by johnping.
    • This reply was modified 2 years, 4 months ago by johnping.
    • This reply was modified 2 years, 4 months ago by johnping.

    I need help regarding my login system. In my project when a user logs in they simply go to the home page. If they are browsing some pages and asked to login then they should redirect to that page after login and not their profile page/home page.
    I have tried both of these code snippets but does not help.

    Thread Starter johnping

    (@johnping)

    Hi@rajandangi649,

    If you want to add my code into Child theme’s functions.php, try the following snippet:

    add_action( 'wp_footer', 'my_footer_scripts' );
    function my_footer_scripts(){
      ?>
      <script>
    jQuery(document).ready(function($){
    var lailu=document.referrer;
    console.log(lailu);
    $("input[name='redirect']").val(lailu);
    $("input[name='ur-redirect-url']").val(lailu);
    });
      
      </script>
      <?php
    }

    Hope it works.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘redirect to last/previous page after user log-in/registration?’ is closed to new replies.