- This topic has 27 replies, 2 voices, and was last updated 10 years, 2 months ago by
Syam Mohan.
-
AuthorPosts
-
August 11, 2015 at 3:08 am #14191
Bratt
SpectatorI diden’t get it to work, does it work for you ?
August 11, 2015 at 9:27 am #14228Syam Mohan
KeymasterCan you also check your PHP opcache revalidation setting?
August 11, 2015 at 11:20 pm #14250Bratt
SpectatorDo you have any tips for where i can find the setting except contact my hosting company?.
August 12, 2015 at 6:56 am #14277Syam Mohan
KeymasterAre you hosting on a shared server or VPS?
I’ll give it another try since you disabled Wordfence.
Thanks
August 12, 2015 at 1:36 pm #14309Bratt
SpectatorIt’s a shared server.
August 12, 2015 at 6:33 pm #14318Syam Mohan
KeymasterHi 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
August 13, 2015 at 3:08 am #14338Bratt
SpectatorMuch appreciated ! =)
August 15, 2015 at 5:49 pm #14462Syam Mohan
KeymasterHi 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
August 19, 2015 at 11:12 pm #14773Syam Mohan
KeymasterHi Bratt,
Does the code work?
Thanks
Syam
August 20, 2015 at 11:53 pm #14887Bratt
SpectatorHi!
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.
August 21, 2015 at 4:59 am #14905Syam Mohan
KeymasterHi 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
August 24, 2015 at 2:22 am #14985Bratt
SpectatorWorks like a charm 🙂
August 24, 2015 at 8:42 am #14998Syam Mohan
KeymasterGlad to help.
Thanks
-
AuthorPosts
- The topic ‘If logged in redirect to Login Redirect url?’ is closed to new replies.
