Redirect from custom login to current page
-
Your plugin looks very good and makes easy for front end registration/login. But I miss the function to redirect from the current page.
My case is: If the user is on page X and logs in, he should return to page X.My current scenario:
I use your shortcode
[user_registration_login]
on custom page called “login”.This function for login in the sidebar:
wp_login_url( get_permalink() );
I get back to the wp standard login page.
Okay, I can handle this with add_filter. And I put this function to functions.php:if ( !function_exists('my_login_page') ) : add_filter( 'login_url', 'my_login_page', 10, 3 ); function fa_login_page( $login_url, $redirect, $force_reauth ) { $login_page = home_url( '/login/' ); if ( ! empty( $redirect ) ) { $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_page ); } return $login_url; } endif;
Now I’m back on the right login page. I see in your form that the hidden field
<input type="hidden" name="_wp_http_referer" value="/login/?redirect_to=http%3A%2F%2Ftestwebsite.local%2Fhello-world%2F">
contains the value/login/?redirect_to=http%3A%2F%2Ftestwebsite.local%2Fhello-world%2F
It should be without/login/?redirect_to=
.How can I handle this or do you have any other way I can handle this?
Best Matthias
- The topic ‘Redirect from custom login to current page’ is closed to new replies.