XF 2.2 How to remove the letter Z from avatars?

Dkf

Active member
If a user does not have an avatar, the forum generates an avatar with the letter Z.
How to avoid this?
 
Last edited:
Disable this option.

  • Enable dynamic default avatars

If enabled, an avatar will be dynamically created for users without a custom avatar. This will include a letter and a color based on their username. If disabled, all users without an avatar will receive a default placeholder
 
  • Wow
Reactions: Dkf
I understand why you would want this being from Ukraine, but it is not possible to exclude a single letter from automatic avatar generation.

You need to deactivate automatic generation completely or create an add-on to replace ‚Z‘ with another letter.
 
Edit template modification: PAGE_CONTAINER
Find: </body>
Replace:
Code:
<script>
document.addEventListener('DOMContentLoaded', function() {
    var avatars = document.querySelectorAll('.avatar span[aria-label]');
    avatars.forEach(function(avatar) {
        var ariaLabel = avatar.getAttribute('aria-label');
        if (ariaLabel && /^Z/i.test(ariaLabel.trim())) {
            var newAriaLabel = ariaLabel.replace('Z', '🇺🇦');
            avatar.textContent = '🇺🇦';
            avatar.setAttribute('aria-label', newAriaLabel);
        }
    });
});
</script>
</body>

Thanks to ChatGPT! :p
 
Last edited:
And.... You can also solve this problem like this -
Edit the file \src\XF\Template\Templater.php

Before:
Code:
return '<span class="' . $innerClassHtml . '" role="img" aria-label="' . htmlspecialchars($username) . '">'

Add the line:
Code:
if ($styling['innerContent'] == 'Z') $styling['innerContent'] = 'UA';
 
Back
Top Bottom