Renaming the (anonymous) user

How to change the username for people who are not logged in to your website.

By Bob Ray  |  September 23, 2025  |  3 min read
Renaming the (anonymous) user

By default, the username given by MODX to users who are not logged in is "(anonymous)." A few years back, I wrote an article about changing the name of the anonymous user to something other than (anonymous). The article showed ways to alter the name in case you didn't want anonymous users to be greeted with the phrase "Hello (anonymous)" in the front end of your website. By the way, in case you're wondering about the parentheses, they are actually part of the username for the anonymous user.

In that older article, the name was changed with a plugin attached to OnWebPagePrerender and a snippet to be placed in the page Template. There's now a much easier way to do this.

A Much Easier Solution

There's now a System Setting with the key default_username. MODX uses its value for the name of not-logged-in users. All you have to do is change that value to "Guest" or whatever you like and "(anonymous)" will never appear on your site again. You can also display the anonymous username on a page with this tag:

[[++default_username]]

In code, you can get it like this:

$anonymousUserName = $modx->getOption('default_username');

A Word of Warning

It's unlikely, but there could be code on your site that uses the username to determine if a user is logged in or not. I think in a weak moment a long time ago, I may have even recommended this, because it's much faster than the "Official" way.

It was significantly faster and clearer to do this:

if ($modx->user->get('username' === '(anonymous)')) {
    /* user is not logged in */
}

than this official method:

if (! $modx->user->hasSessionContext($modx->context->get('key'))) {
    /* user is not logged in */
}

If you only have one front-end context (i.e., 'web'). You can speed up the code above by doing this:

if (! $modx->user->hasSessionContext('web')) {
    /* user is not logged in */
}

The two methods above are much better options than checking the username, and now the speed difference is negligible.

I've never checked the username to establish login status in any of my extras, and I doubt if anyone else has done this, but it's a possibility. If you change the default_username System Setting value and not-logged-in users suddenly start getting treated as if they are logged in, or vice versa, you'll know what to look for. Any code that looks like the first example above can easily be converted to match the second or third example.


Bob Ray is the author of the MODX: The Official Guide and dozens of MODX Extras including QuickEmail, NewsPublisher, SiteCheck, GoRevo, Personalize, EZfaq, MyComponent and many more. His website is Bob’s Guides. It not only includes a plethora of MODX tutorials but there are some really great bread recipes there, as well.