Most themes provide a body class “logged-in”, I have used this to show/hide menu items. This could help you keep logged in sessions away from the registration screen.
In php your can use something like this:
if( is_user_logged_in() ) {
wp_redirect('/some-other-url');
}
Hi @vanaf1979
Where should i place that piece of code?
May i have to add another if asking if you are in register page and add in functions?
Thanks for the help.
Hey @cienfu90
The simplest way is to just add it at the top of you register template file.
Or you can add it to your functions php like so:
add_action('after_setup_theme' , function() {
if( $_SERVER['REQUEST_URI'] == '/register' && is_user_logged_in() ) {
wp_redirect('/some-other-url');
}
});
Change /register and /some-other-url to the required slugs/url.
Let me know if this works for you.
Stephan
Hi @vanaf1979
It doesn’t work, still redirecting to the homepage, i try adding it to the functions file on my theme.
-
This reply was modified 3 years, 9 months ago by
cienfu90.
Hey @cienfu90,
Did you change the url’s inside my code example? the “/regsiter” and the “/some-other-url”? You may need to add a slash at the end like so “/regsiter/”!
Yes sure, i am using yootheme and place it on funcionts theme file.
/**
*
*Redirigir a actividad si el usuario ya esta logeado y hace click en registro
*
*/
add_action('after_setup_theme' , function() {
if( $_SERVER['REQUEST_URI'] == '/registro/' && is_user_logged_in() ) {
wp_redirect('/actividad/');
}
});
@vanaf1979 i try with /registro/ and /registro, same, always goes to homepage.
Try using the “init” action instead. I don’t think WP has quite figured out the user status after theme setup.
If that still does not help, error_log the $_SERVER[‘REQUEST_URI’] value and check the result to find out why it’s not matching to /registro/ or what ever.
Hi @bcworkz you mean like this, right?
add_action('init' , function() {
if( $_SERVER['REQUEST_URI'] == '/registro/' && is_user_logged_in() ) {
wp_redirect('/actividad/');
}
});
Doesn’t work 🙁
You need to follow wp_redirect() with an exit;
statement so PHP stops processing the current thread. Otherwise the server thinks it’s still busy.
so it will be like
add_action('init' , function() {
if( $_SERVER['REQUEST_URI'] == '/registro/' && is_user_logged_in() ) {
wp_redirect('/actividad/');
exit();
}
});
will try it later, thanks
Correct. If you still have trouble there’s something wrong the the URI values. I double checked on my site (with different URIs of course) and it works as expected.