You can achieve that using Javascript and login_footer
action hook to change the href
attribute of the Back to
link:
<?php
add_action('login_footer', 'ad_login_footer');
function ad_login_footer() {
$ref = wp_get_referer();
if ($ref) :
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$("p#backtoblog a").attr("href", '<?php echo esc_js($ref); ?>');
});
</script>
<?php
endif;
}
?>
Edit:
Thanks to @brasofilo answer, you might need to load jQuery in wp-login.php
. It might be loaded already by your theme or another plugin, so you have to check. To load jQuery in order to use the above code:
add_action('login_head', 'jquery_for_wp_login');
function jquery_for_wp_login() {
wp_print_scripts(array('jquery'));
}
Related Posts:
- Custom login form redirect to external site
- Clarification on auth_redirect()
- How to redirect all requests to wp-login.php?
- Redirect user after login/registration globally
- Remove lost password form and URL
- How to auto login after registration? [duplicate]
- Redirect away from login page
- Redirect when accessing /login when logged in
- Redirect outside WP after login
- wp_login_form redirect problem
- How to redirect wp_login_form to new page after user loged in?
- redirect doesn’t work while using example code
- Disable redirect to homepage after successful Login, Stay on Current Page
- wp_login_form() redirect same page
- Determine user destination on wp-login.php
- Redirect after login when WordPress in subdirectory
- Login redirects to home page and doesn’t log in
- Custom login-form redirect
- Login Form Redirection
- Redirect user to login and then to page where they came from
- Redirect Restricted Page to 404
- Site redirects to wrong url when saving settings
- Redirect blog page to latest post?
- WordPress site redirects to different wordpress domain on the same server after reuploading db backup
- How to redirect users to custom lostpassword page?
- Links to an exisiting Page are now redirecting to a draft page?
- add_rewrite_rule to pass entire path as a single parameter
- htaccess redirect dynamic posts
- RedirectMatch and Redirect interfering with each other
- Redirect all pages to homepage but still allow dashboard
- Return to where the user was, after log out
- How to modify the Register link in the login page?
- Changing “Lost Password Email Link” to custom password reset page
- Redirect a page id url but not the page slug
- Redirect based on parameter in url
- htaccess redirect – replace special character
- Redirect Logged In User if page is wp-login.php and $_Get[‘level’] = X
- Right hook to redirect frontend visitors while respecting rest api plugins to run first?
- Redirect loop after changing nameserver [closed]
- Is it possible to incorporate username in a login redirect?
- How to make wordpress folder (/wordpress) redirect to /?
- How to redirect on login to a specific page if a specific meta user is empty
- Redirecting amp url to non amp url
- How To Redirect /url.html to /url?
- Remove #wpcf7-f2450-o1 with Contact form 7 redirect [closed]
- Redirecting deleted posts url to another WordPress install
- Redirect – remove custom query string
- 301 redirect from old URL structur to new
- Redirect each user to specific pages based on their role
- How to fix too many redirects when enabling SSL for site?
- Add Username to URL for redirect
- Log out and redirect to different URL
- How to get better performance for redirect from domain.tld/35 to domain.tld/full-permalink?
- Redirect deleted page URL ?p=xxxx
- Have WordPress post redirect to url when accesed from iPad (Safari)
- I want to resolve Redirect Chain [closed]
- How to fix URL with pageid example /?p= too many redirection error
- Conditional redirect to several pages
- Display Freebie Page Content only if Referrer is from Form Page
- simple wordpress form redirection
- Redirect to home if page doesn’t exists [duplicate]
- Redirect all links form a category to new links on new category
- My redirect URL doesn’t show any pages on my website [closed]
- Cannot install wordpress, /wp-admin/install.php, inproper redirection [closed]
- How to redirect logged out users to specific page?
- Login redirect shows white page in firefox
- Date based redirects of posts that no longer exist
- redirect wordpress post to new subfolder site on same domain
- 301 all old pages to new location
- How do I share a site only to one User at the time? Please help 🥺🙌
- Re-Direct ALL Users to the Home Page IF not logged in
- Redirect to dashboard user once you click on Publish page
- Author Archive Page redirecting issue
- Understanding Redirects
- How to redirect returning users who previously logged in?
- Why https://www. SUBdomain is redirected by WP to https://MAINdomain
- Page editing in backend redirecting to 404 page not found with url /post.php
- wordpress redirect error in xampp
- Swapping current old site to new WordPress site – need to check I’m doing it right
- how redirect users to custom login page when user comment must “login to reply” is clicked?
- How to redirect a referal url to a signup page?
- Allow GET request on certain page
- .htaccess redirect for old subfolder installation to new subfolder installation and https
- How to modify the WordPress comes with redirect
- Conditional redirect on login using referring URL
- PHP Mistake – Whats wrong here?
- WordPress update 4.4.1 redirect loop
- Redirecting Issue
- htaccess and redirect to new url using regex
- redirect attachment page to category page
- 301 redirect for wordpress permarlink
- Google PageSpeed: Avoid landing page redirects?
- Need rewrite for URL with specific string
- Redirect to 404.php from single.php
- How to Show different page URL instead of default home page URL
- How to Redirect Url to homepage?
- 404 Not Found with All Cloaking plugins
- How to Create Custom Route to a page in WordPress
- How to create a redirect to another domain like safe redirect manager from php
- Post Migration Site Migration Redirects All Known Solutions Attempted