Authentication Reference
Customer Dashboard Login
After a customer logs into the dashboard, you can use the sc_login_redirect_url
filter hook to redirect them to any URL. This includes:
- Absolute URLs (e.g., https://example.com/courses)
- Relative paths (e.g., /courses)
- Internal pages using home_url()
- External websites
Here's the template code you should use:
add_filter( 'sc_login_redirect_url', function( $url ) {
// Examples:
// return '/courses'; // Relative path
// return 'https://external-site.com/dashboard'; // External URL
// return home_url('/member-area'); // Internal URL using home_url()
return home_url(); // Redirect to homepage
}, 10, 1 );
Real-world example:
This filter customizes the login redirect URL based on the user's role. Students, instructors, and administrators are redirected to specific pages, while others follow the default redirect.
add_filter( 'sc_login_redirect_url', function( $url ) {
// Get current user role.
$user = wp_get_current_user();
$role = $user->roles[0];
// Different redirects based on user role.
switch ($role) {
case 'student':
return '/courses/';
case 'instructor':
return home_url('/teacher-dashboard');
case 'administrator':
return admin_url();
default:
return $url; // Default url - redirected to the customer-dashboard.
}
}, 10, 1 );
Updated 3 days ago