Redirection after successful login
Hi Shahjahan Jewel, how can I redirect users to a specific URL after a successful login?
I'm using FluentCommunity login page.
I've configured a redirection using a small code snippet, it's working with the default wp-login.php, but not with FC login page.
I'm trying to redirect users to /portal/courses?type=enrolled instead of the feed.
Can you please help me?
SOLVED, using ChatGPT
add_filter('fluent_community/auth/after_login_redirect_url', function ($redirectUrl, $user) {
// Default redirection URL for non-admin users
$customRedirectUrl = 'https://example.com/your-target-page';
// Check if the user has the administrator role
if (user_can($user, 'administrator')) {
// Redirect administrators to the WordPress admin dashboard
$customRedirectUrl = admin_url();
}
// Return the redirection URL
return $customRedirectUrl;
}, 10, 2);
Explanation:
-
Default behavior: Non-admin users are redirected to https://example.com/your-target-page.
-
Admin users: Redirected to the WordPress admin dashboard.
-
Filter specificity: The fluent_community/auth/after_login_redirect_url filter ensures that the redirection applies specifically to FluentCommunity logins.
Nasser-eddine BENAZIZAΒ can also use https://fluentauth.com/
Debo OgunrindeΒ not working for me. I tried it before asking ChatGPT.
You can do it with a Free FluentAuth plugin and redirect your users to any URL (ex. /portal) based on their User Role.
Mat βΒ It's working on your side using FluentAuth?
Not working at all on my side.
I've tried before using ChatGPT π
Nasser-eddine BENAZIZAΒ Yes it works for me. You need to select a User Role: Subscriber for redirection to your specific URL
Mat βΒ I tried with specific user role, not working. I tried using default redirect after login, not working also.
Maybe something on my side.. but using this snippet is now working properly.
https://fluentauth.com/ plugin works for me...It also has some security benefits...
Debo OgunrindeΒ I'm using it as well, but not for the redirection. I will give it another try, maybe I will be able to find what is not working for the redirection process.
Debo OgunrindeΒ FluentAuth's custom redirection is not working for me neither. I will try that code Nasser-eddine BENAZIZAΒ shared. Thanks in advance
Debo OgunrindeΒ FluentAuth isn't working for me either. Still redirecting to the general feed page. I wouldn't have an issue with it, but when posting there, you have to select a space to post in the right space, and I don't want to overcomplicate it for my community members. I can have the general posting allowed but then that isn't specific to one space. I am using the automation to auto-join my members to the main space and then redirect them to the main space after log in using the code provided above.
hi there,
can i use the snippet with a dynamic url?
my problem: i get a notification email about a new comment with a deeplink:
"show the comment"
...../portal/space/start-here/post/englisch-schulaufgabe-bewertungen?comment_id=9&fcom_action=signed_url&fcom_url_hash=2743f7e31477217b1c5ddecaa55e1d8d__15
when i click, i come to the login form from FC, after login the redirect goes to wp-admin/profile.php
any idea?
Helmut PlarreΒ Hi, the snippet should work with dynamic URL. You should test it and tell us if it's working, or maybe ask AI for a workaround if it's not working.
Please keep us updated!