---
title: "Redirect Users After Login by User Group in Joomla - Code Snippets"
description: "Send members, authors and administrators straight to the right page the moment they log in to your Joomla site, using one PHP snippet."
url: "https://www.tassos.gr/docs/code-snippets/howto/access-control-security/redirect-after-login"
date: "2026-10-22T23:05:02+00:00"
language: "en-GB"
---

[ Home ](https://www.tassos.gr/docs) / [ Code Snippets ](https://www.tassos.gr/docs/code-snippets) / [ How-to Guides ](https://www.tassos.gr/docs/code-snippets/howto) / [ Access Control & Security ](https://www.tassos.gr/docs/code-snippets/howto/access-control-security)

#  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.

 ![Redirect Users After Login by User Group in Joomla](https://www.tassos.gr/images/2026/10/code-snippets-redirect-after-login-card.png) Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

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-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](#how-to-add-this-snippet)

1. Install [Code Snippets](https://www.tassos.gr/docs/code-snippets/getting-started/how-to-install) if it isn't installed already.
2. Log into your Joomla backend.
3. Go to **Components** → **Tassos Code Snippets**.
4. Click **New**.
5. Enter a title, for example *Redirect after login*.
6. Set **Code Type** to **PHP**.
7. Set **Insertion Method** to **Auto-Insert Locations**.
8. Set **Location** to **On Page Load**.
9. Paste the code above into the editor.
10. Replace the sample group IDs and pages with your own.
11. 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](#check-that-it-works)

1. Open your site's login page in a private browser window.
2. 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](https://www.tassos.gr/docs/code-snippets/howto/access-control-security/login-with-email). The 2 snippets work together. To learn more about how PHP snippets work, read the [PHP snippet docs](https://www.tassos.gr/docs/code-snippets/types/php).

 Last updated on Oct 15th 2026 18:10
