The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

How to set maximum username length (4 posts)

  1. chulk607
    Posted 6 years ago #

    60 characters seems a tad excessive and is causing my theme to explode in extreme cases. Users with extremely long usernames are causing hell in my forum which pulls the usernames straight from WordPress.

    Is there any way of reducing this number (without hacking the code preferably)? I'd like to set it to, say, 20 characters... a value, which to my mind seems rather reasonable.

    As I say, I'd rather not hack the hell out of the code ideally, mainly to avoid issues caused by future updates. However, if anyone does know where to find the code that would target this, please do chime in.

    Am I missing something obvious?

  2. Agus Suhanto
    Posted 6 years ago #

    There is a filter called 'pre_user_login' that you can use to alter the username after being submitted by the user.

    Inside this filter you can cut the username length to the number you desired. This doesn't affect core WordPress code. You can write the filter inside functions.php of theme you are using.

  3. kallumamaji
    Posted 5 years ago #

    A similar post can be found in the forum titled "limiting username length" but it doesnt work for newer wordpress software.

    A slightly modified version can be found on a post "How to limit username length in wordpress?" It worked for me.

  4. dorothai
    Posted 5 years ago #

    there is no more registration.php in wp-include WP 3.1.3
    The other problem is that users actually register even with 3 letter username which causes problems too, as most db's are configured to request at least 4 characters for a search.
    Better solution: $valid = strlen($username) > 5 && strlen($username) < 30;

Topic Closed

This topic has been closed to new replies.

About this Topic