How to Set a Maximum Length for Usernames?
In UsersWP, you can easily set a max length attribute for usernames, thereby ensuring that usernames cannot be longer than the specified length value.
Code Snippet to Set Max Length Attribute for Usernames
You can use the following code snippet to set the max length attribute for usernames upon registration.
We recommend using the Code Snippets plugin.
add_action( 'uwp_template_after', 'uwp_template_after_custom_callback' ); function uwp_template_after_custom_callback($type){ if( 'register' == $type ){ ?> <script> jQuery(document).ready(function(){ jQuery(".uwp-registration-form #username").prop('maxlength','6'); }); </script> <?php } }
The above code will limit the maximum length of usernames to six characters. You can replace the numeric value to any value of your choice.