We have a custom login page (/login) and I need help with redirecting back to a previous URL.
All pages redirect to the login page unless they are on the login page, register page, password-reset page, contact page or email-activated page.
Right now, once the user logs in, they are redirected to the **home\_url();**.
I created a survey in which they will need to be logged in to submit but my issue is that once they are logged in, it just go to the homepage vs redirecting back to the previous page.
function display_login($atts) {
ob_start();
$args = array(
‘echo’ => false,
‘redirect’ => home_url(),
‘label_username’ => ‘Username or Work Email’,
‘label_log_in’ => ‘Submit’,
‘remember’ => false,
);
echo wp_login_form($args);
return ob_get_clean();
}
add_shortcode(‘custom_login_form’, ‘display_login’);
I’ve tried changing **home\_url()** to **wp\_get\_referer()** but it would just go from **/login** (custom login page) to **/wp-login** (wp-login page).
Is there a way to default redirect to home\_url() but if they come in on a different link (say they bookmarked a page), the redirect takes them back to that page?
How do I go about doing that?
[ad_2]
If you google [https://www.google.com/search?q=wordpress+login+page+redirect+to+previous+page])
You’ll find several answers, like [https://wp-content.co/redirect-after-login/]) and