-
-
- Submit Updated Articles to Bing and Yandex with IndexNow in Joomla
- Add Published and Modified Date Meta Tags to Joomla
- Add Open Graph and Twitter Card Tags to Joomla
- Auto-Generate Meta Descriptions from Article Text in Joomla
- Add Noindex to Specific Pages in Joomla
- Verify Your Joomla Site with Google Search Console
-
- Add a View as Markdown Link to Joomla Articles
- Display the Last Modified Date in Joomla Articles
- Embed Iframes in Joomla
- Automatically Link Twitter (X) @mentions in Joomla Articles
- Open External Links in a New Tab in Joomla
- Display Estimated Reading Time in Joomla Articles
- Replace Old URLs in Joomla
- Search and Replace in Joomla
-
- Add a Footer Line to the Joomla Administrator
- Show a Staging Banner in the Joomla Administrator
- Remove the "All" Option from Admin List Limits in Joomla
- Add a Cookie Consent Banner to Joomla
- Make the Administrator Navigation Sticky in Joomla
- Add Google Fonts to Joomla
- Add a Facebook Messenger Chat Button to Joomla
- Add a Reading Progress Bar to Joomla
- Add a Custom Scrollbar to Joomla
- Show Confetti on a Thank You Page in Joomla
- Add Smooth Scrolling to Joomla
- Add a Back to Top Button in Joomla
- Add a WhatsApp Chat Button in Joomla
-
- Protect the Administrator with a Secret URL Key in Joomla
- Show a Welcome Message on First Login in Joomla
- Log Out Idle Administrators in Joomla
- Assign New Users to a Different User Group Automatically in Joomla
- Redirect Visitors by Country in Joomla
- Redirect Users After Login by User Group in Joomla
- Block User Registration with Certain Usernames in Joomla
- Block User Registration by Country in Joomla
- Block User Registration by Email Address in Joomla
- Block User Registration by IP Address in Joomla
- Remove the Forgot Password and Username Links in Joomla
- Remove the Generator Meta Tag in Joomla
- Let Users Log In with Their Email Address in Joomla
- Block Traffic by Country in Joomla
- Block Bot Traffic in Joomla
- Block Traffic by IP Address in Joomla
Redirect Users After Login by User Group in Joomla
Send members, authors and administrators straight to the right page the moment they log in to your Joomla site, using one PHP snippet.
Your members log in and land on their profile page, the one page most of them never asked for. Customers should see their downloads, authors their articles, and staff their dashboard. Joomla's login menu item and login module each take a single redirect page for everyone. You can send each user group to its own page after login with one PHP snippet in Code Snippets.
The PHP snippet code
The snippet waits for a successful login on your site, checks the user's groups, and changes the page Joomla opens next.
use Joomla\CMS\Factory;
// User group ID => the page that group sees after logging in.
// If a user belongs to more than one of these groups, the first one wins.
$redirects = [
8 => 'index.php?Itemid=101',
3 => '/author-dashboard',
2 => '/members',
];
// Do not edit below.
$app = Factory::getApplication();
$app->registerEvent('onUserAfterLogin', function ($event) use ($app, $redirects)
{
$user = $event->getOptions()['user'] ?? null;
if (!$user)
{
return;
}
$groups = array_map('intval', $user->groups);
foreach ($redirects as $groupId => $url)
{
if (in_array((int) $groupId, $groups, true))
{
// Joomla's login form reads this to pick the page after login.
$app->setUserState('users.login.form.return', $url);
return;
}
}
});
Edit the $redirects list. Each line pairs a user group ID with a page:
- Group IDs are in the ID column of Users → Groups. On a new Joomla site, Registered is 2, Author is 3 and Super Users is 8.
- Pages can be a menu item, written as
index.php?Itemid=101, a path like/members, or a full address. Menu item IDs are in the ID column of Menus → All Menu Items. - Users in several listed groups go to the page of the group that comes first in the list, so put your most specific groups at the top.
The snippet checks the groups ticked in the user's Assigned User Groups tab. A custom group that sits inside Registered needs its own line, because it doesn't pick up the Registered redirect.
Users who aren't in any listed group keep Joomla's usual redirect. For the listed groups, the snippet replaces the redirect set in a login menu item or login module.
How to add this snippet
- Install Code Snippets if it isn't installed already.
- Log into your Joomla backend.
- Go to Components → Tassos Code Snippets.
- Click New.
- Enter a title, for example Redirect after login.
- Set Code Type to PHP.
- Set Insertion Method to Auto-Insert Locations.
- Set Location to On Page Load.
- Paste the code above into the editor.
- Replace the sample group IDs and pages with your own.
- Click Save & Close.
PHP snippets run on the frontend of your site only, so logging into your Joomla administrator works as before.
Check that it works
- Open your site's login page in a private browser window.
- Log in with a user from one of the groups on your list.
You should land on that group's page. Log in with a user from a group that isn't on the list, and Joomla sends them to its usual page instead.
To let users log in with their email address too, see Let Users Log In with Their Email Address in Joomla. The 2 snippets work together. To learn more about how PHP snippets work, read the PHP snippet docs.