-
-
- 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
Block User Registration with Certain Usernames in Joomla
Keep names like admin, support or your brand out of the hands of new members by rejecting reserved usernames and patterns at sign-up, using one PHP snippet.
Someone registers as "support" or "admin" and starts posting in your forum, and other members take them for staff. Or a new user picks your brand name and you can't use it for your own account later. Joomla only checks that a username is free, not whether it's a name you want to give away. You can block user registration with certain usernames in Joomla with one PHP snippet in Code Snippets.
The PHP snippet code
The snippet runs right before Joomla stores a new account. When the username matches your list, Joomla cancels the registration and shows your message on the form, and the visitor can pick another name. Logins, profile edits and existing accounts aren't affected.
use Joomla\CMS\Factory;
// Usernames no one can register. A * matches anything, so 'test*' covers
// test, test1 and tester, and '*joomla*' covers any name that contains joomla.
$blockedUsernames = [
'admin',
'administrator',
'root',
'support',
'test*',
'*joomla*',
];
// Message shown on the registration form instead of the welcome message.
$message = 'This username is not available. Please choose another one.';
// Do not edit below.
$app = Factory::getApplication();
$app->registerEvent('onUserBeforeSave', function ($event) use ($blockedUsernames, $message)
{
// Only new accounts. Profile edits pass through.
if (!$event->getArgument('isNew', $event->getArgument(1, false)))
{
return;
}
$data = $event->getArgument('data', $event->getArgument(2, []));
$username = strtolower(trim($data['username'] ?? ''));
foreach ($blockedUsernames as $pattern)
{
$pattern = strtolower(trim($pattern));
if ($pattern !== '' && fnmatch($pattern, $username))
{
// Joomla cancels the registration and shows this message.
throw new RuntimeException($message);
}
}
});
Change the 2 settings at the top:
$blockedUsernames: the names no one can register. A plain entry likeadminblocks that exact name. A*matches anything, sotest*blocks test, test1 and tester, and*joomla*blocks any name that contains joomla. The list isn't case sensitive, soadminalso blocks Admin and ADMIN.$message: the text Joomla shows on the registration form. It appears after "Registration failed:".
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 Block reserved usernames.
- 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 names with the ones you want to reserve.
- Click Save & Close.
Check that it works
- Open your site's registration page in a private browser window.
- Submit the form with the username
tester.
Joomla shows "Registration failed: This username is not available. Please choose another one." and creates no account. Submit the form again with a name that isn't on the list, and the registration goes through.
To block sign-ups by IP address, email address or country, see Block User Registration by IP Address in Joomla, Block User Registration by Email Address in Joomla and Block User Registration by Country in Joomla. To learn more about how PHP snippets work, read the PHP snippet docs.