Redirect member back to URL after they log in
-
I using WP User Manager and I have some content that is for members only, when a logged out user tries to access it they are redirected to the login page.
So for example a non-logged in user goes to “https://incitenbstage.wpengine.com/supplier/brakes/” and is redirected to “https://incitenbstage.wpengine.com/log-in” and they login they are then redirected to the default logged in homepage instead of the previous page. I have the below code using a filter from the WP User Manager plugin, currently when I log in after clicking on gated content with the below code I get https://incitenbstage.wpengine.com/log-in/https://incitenbstage.wpengine.com/log-in
Has anyone been any to redirect back to the previous URL once a user logs in? It seems to work with the standard WordPress login form but no the custom WP User Manager one
Anyone have any suggestions?
// ** CAPTURE CLICKED LINK BEFORE LOGIN **/ add_action( 'wp', 'sc_capture_before_login_page_url' ); function sc_capture_before_login_page_url(){ if( !is_user_logged_in() ): $_SESSION['referer_url'] = get_the_permalink(); endif; } // ** REDIRECT **/ add_filter( 'wpum_redirect_after_login', 'my_wpum_redirect_after_login', 10, 2 ); function my_wpum_redirect_after_login( $redirect, $user ) { $url = $_SESSION['referer_url']; if ( ! $url ) { return $redirect; } // If whole of the URL then return $url return home_url( $url ); }
- The topic ‘Redirect member back to URL after they log in’ is closed to new replies.