- This topic has 9 replies, 4 voices, and was last updated 6 years ago by
Tom.
-
AuthorPosts
-
May 23, 2020 at 3:12 pm #1298544
Maria
I’m trying to redirect logged-in users to a Members Only Home page when they log in. I tried the code below per David’s response on 2/7/20 #1157775 and changed ‘/logged-in-home’ to the page slug of the page I want to redirect them to but it doesn’t work. I’m currently using Peter’s Login Direct plugin but it’s causing me other issues and I’d like to get rid of that plugin. Am I missing anything from the code below?
add_action( ‘wp’, function() {
if ( is_front_page() && is_user_logged_in() ) {
wp_redirect( home_url( ‘/logged-in-home’ ) );
die();
}
} );May 23, 2020 at 6:15 pm #1298637Grant
May 23, 2020 at 8:07 pm #1298677Maria
Doesn’t help me. I have no idea what the $page = 2516 or update_option means. David’s code makes sense to me but seems like something is missing. Any other options?
May 24, 2020 at 2:28 am #1298931David
StaffCustomer SupportHi there,
where and how are you adding the code?
For reference this is the working code i just tested:
add_action( 'wp', function() { if ( is_front_page() && is_user_logged_in() ) { wp_redirect( home_url( '/logged-in-home' ) ); die(); } } );May 24, 2020 at 4:27 am #1299090Maria
Where and how should I be adding the code?
May 24, 2020 at 6:43 am #1299207David
StaffCustomer SupportIt’s PHP – this document explains:
May 24, 2020 at 8:39 am #1299436Maria
I realize it’s PHP. I was hoping for a bit more explanation. I put the following snippet in the functions.php of my child theme.
add_action( ‘wp’, function() {
if ( is_front_page() && is_user_logged_in() ) {
wp_redirect( home_url( ‘/members-home-page’ ) );
die();
}
} );After logging in, I was directed to the Dashboard, not the Members Home Page I intended. I don’t know what I’m doing wrong.
May 24, 2020 at 4:00 pm #1299774Tom
Lead DeveloperLead DeveloperHi there,
How are you logging in?
That code will redirect a logged-in user if they go to the front page. It won’t necessarily redirect them as soon as they log in.
In order to redirect someone from the login form, you would need them to go to the login form using a specific link.
If you search for “WordPress redirect after login”, you should find a lot of answers. This one looks promising: https://stackoverflow.com/a/8127629/2391422
May 24, 2020 at 6:08 pm #1299858Maria
Thanks, Tom for the explanation. I totally understand now. I wanted to redirect them as soon as they log in.
May 25, 2020 at 9:21 am #1300817Tom
Lead DeveloperLead DeveloperNo problem! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.