WordPress functionality to redirect a specific page to the login page and then back to that page
P粉794851975
2023-08-30 16:27:52
<p>I searched online and on stackoverflow but didn't find what I wanted, this is my situation</p>
<p>I want to redirect users who want to access a specific page to the login URL and then redirect them to the previous page
I used the following code</p>
<pre class="brush:php;toolbar:false;"><?phpif ( is_user_logged_in() || ! is_page() ) return;
$restricted = array( 5049 ); // All restricted pages
if ( in_array( get_queried_object_id(), $restricted ) ) {
$previous_url = $_SERVER['HTTP_REFERER'] ? : site_url( '/user-account' );
wp_redirect( $previous_url);
exit();
}});</pre>
<p>The first part worked fine, I was redirected to the login page, but then not redirected to the old page</p>
<p>I would like to know how to redirect to the page the user wants to visit after successful login</p>
Create your own login page using redirect parameters: