Hi,
I need to append ?cachen to the url a user logs in and the page is reloaded. I want to keep them on the same page, just append that.
Looking at the wordpress documentation, it looks like I should be able to use something like this in functions.php:
////////
function nf_redirect( $redirect_to, $request, $user ) {
return $request.”?cachen”;
}
add_filter( ‘login_redirect’, ‘nf_redirect’, 10, 3 );
///////
However, this has been ineffective. It just doesn’t work.
So… I’m wonder if perhaps Newsmag isn’t using wp-login.php and maybe has it’s own login script?
If so, I can’t find it.
Can you either tell me where the Newsmag login script is or why my redirect function isn’t working?
Thanks!
Chris
PS: In case you are wondering, the reason is that I use cloudflare and even when a user is logged in, they still get cached content instead of fresh if using the unaltered url. I need them to get the freshest page, and my cloudflare is set up to not serve a cached page if they find ?chachen in the url. After they are logged in, I set a cookie and it’s served fresh, but the first page after log in isn’t set in time for the cookie to be active yet.
Hi,
Theme’s login widget does use wp’s login system. You can find it here: http://screencast.com/t/p18U0cDm and you can try your redirect function using a default theme to test if it actually works.
Hope you’ll find this useful!
Thanks for the message!
Hi Lucian,
Thank you.
I’ve been working with the widget and trying different things that haven’t worked.
I can’t figure out where the login redirects back to the page the user is on. That’s what I need to find to append the ‘?cachen’
I found the function I tried (above) only affects logging in directly from the backend. Won’t work for logging in through the front end.
Let me know if you have further ideas on what I might change to do this,
Thanks,
Chris
Hi
The theme redirect the user to the homepage when logs out from the site: http://screencast.com/t/DDsl4djXlk You can change that function with a custom link or a different redirect.
If you want to redirect users to a custom page after they log in on your site then you can use a similar implementation with this one presented in WordPress docs in functions.php file: https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect
Hope this help.
Thanks!
Hi AndreiL,
Thank you very much for helping with this.
If you want to redirect users to a custom page after they log in on your site then you can use a similar implementation with this one presented in WordPress docs in functions.php file: https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect
Yes, that is the behavior I was expecting. I’m using (from the example on that page):
add_filter( ‘login_redirect’, create_function( ‘$url,$query,$user’, ‘return home_url(“/?cachen”);’ ), 10, 3 );
and that works IF a user logs in to the admin, like through wp-admin.php They get redirected to the home page with the /?cachen
But if they log in through the front end using the newsmag login, that function doesn’t seem to kick in, the page they are on just refreshes as is,
Chris
Hi
When user log in to your website on frontend the theme send a request to the admin-ajax.php file. To apply a redirect or change the link after user log in you will need some customizations in theme’s js: http://screencast.com/t/HCLVh7WjgjB
This is a complex task which require many customizations and unfortunately I can’t offer a solution now. If you still need guidance on this or you’re not aware of the steps you need to take in this regard please consider hiring a developer or a freelancer to do this for you as we can’t offer customization services at the moment.
Thanks!
