-
-
- 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
Assign New Users to a Different User Group Automatically in Joomla
Put every new member straight into the user group you choose, instead of moving accounts by hand after each sign-up, using one PHP snippet.
Joomla puts every new account into one group, the one set under Users → Options → New User Registration Group. When your members should start as Authors, or in a custom Members group with its own access level, you end up moving each account by hand. You can assign new users to a different user group automatically in Joomla with one PHP snippet in Code Snippets.
The PHP snippet code
The snippet runs right after Joomla stores a new account and moves it into the group you choose. Profile edits and existing accounts aren't touched.
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\UserGroupsHelper;
use Joomla\CMS\User\UserHelper;
// The ID of the group new users join. Find it under Users -> Groups.
$groupId = 3;
// true: the group above replaces the default group from the Users options.
// false: new users join the group above on top of the default one.
$replaceDefault = true;
// Do not edit below.
$app = Factory::getApplication();
$app->registerEvent('onUserAfterSave', function ($event) use ($groupId, $replaceDefault)
{
$isNew = $event->getArgument('isNew', $event->getArgument(1, false));
$saved = $event->getArgument('savingResult', $event->getArgument(2, false));
$user = $event->getArgument('subject', $event->getArgument(0, []));
$userId = (int) ($user['id'] ?? 0);
// Only new accounts that Joomla saved. Profile edits pass through.
if (!$isNew || !$saved || !$userId)
{
return;
}
// A group that doesn't exist would break the registration, so check first.
if (!UserGroupsHelper::getInstance()->get((int) $groupId))
{
return;
}
if ($replaceDefault)
{
UserHelper::setUserGroups($userId, [(int) $groupId]);
return;
}
UserHelper::addUserToGroup($userId, (int) $groupId);
});
Change the 2 settings at the top:
$groupId: the ID of the group new users join. Go to Users → Groups and read it from the ID column. On a fresh Joomla site, Registered is 2, Author is 3 and Editor is 4.$replaceDefault: keeptrueto make this group the only one a new user belongs to. Set it tofalseto add the group on top of the default one.
When the ID doesn't match any group, the snippet does nothing and the new user keeps the default group, so a typo can't break registration.
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 New users to Authors.
- 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 ID with your own.
- Click Save & Close.
Use a different group for one registration page
When your site has more than one registration page, for example one for customers and one for partners, limit the snippet to the page whose sign-ups should land in the new group. Open the snippet, go to the Conditional Logic tab, set Display on to Selected Pages, add a Menu or URL - Query String condition that matches that page, and save. Sign-ups from the other pages keep the default group.
Learn more in Conditional Logic.
Check that it works
- Open your site's registration page in a private browser window and create a test account.
- In your Joomla backend, go to Users → Manage and open the new account.
The Assigned User Groups tab shows the group from $groupId ticked, and with $replaceDefault set to true the default group isn't.
To send members of each group to their own page after they log in, see Redirect Users After Login by User Group in Joomla. To learn more about how PHP snippets work, read the PHP snippet docs.