- This topic has 27 replies, 2 voices, and was last updated 9 years, 4 months ago by .
- The topic ‘If logged in redirect to Login Redirect url?’ is closed to new replies.
I diden’t get it to work, does it work for you ?
Can you also check your PHP opcache revalidation setting?
Do you have any tips for where i can find the setting except contact my hosting company?.
Are you hosting on a shared server or VPS?
I’ll give it another try since you disabled Wordfence.
Thanks
It’s a shared server.
Hi Bratt,
It seems like the caching is still there. I’ll try to do the code on one of my development sites and send it you. It will take me sometime, since I need to setup the testing environment.
Thanks
Syam
Much appreciated ! =)
Hi Bratt,
The reason it was not working because its too late to redirect from a page template.
function login_page_template_redirect() { if(is_page('login')) { if(is_user_logged_in()) { wp_redirect(apply_filters('login_redirect', '/')); } else { wp_redirect('/wp-login.php'); } exit(); } } add_action( 'template_redirect', 'login_page_template_redirect' );
Try putting the above code within the functions.php.
Thanks
Syam
Hi Bratt,
Does the code work?
Thanks
Syam
Hi!
Sorry, i had totally missed your answer =)
Tried it this morning and it works great as it seams. It gives error if the user’s role has no redirect role.
ERR_TOO_MANY_REDIRECTS
Like admin account but that is something that is acceptable.
Your the hero of the year!! Wow, thanks for the exceptionally grate support.
Hi Bratt,
The reason you are getting that error is, that code specifies the home page(‘/’) as the default redirect location if no login redirects found for that user. But your home page also uses this template. So it goes into a redirect loop. You will have the same error, if the URL configured within the login redirect uses the same template/code.
To fix the error, change the default location to a URL which do not use this template/code. For example, change it to ‘/abc/’ and make sure page ABC do not use this template/code.
So your code will change like this.
wp_redirect(apply_filters('login_redirect', '/abc/'));
Let me know if it doesn’t work.
Thanks
Syam
Works like a charm 🙂
Glad to help.
Thanks