{"id":128,"date":"2025-02-06T12:40:04","date_gmt":"2025-02-06T12:40:04","guid":{"rendered":"https:\/\/documentation.userswp.io\/article\/how-to-set-a-maximum-length-for-usernames\/"},"modified":"2025-03-26T15:39:38","modified_gmt":"2025-03-26T15:39:38","slug":"how-to-set-a-maximum-length-for-usernames","status":"publish","type":"gd_place","link":"https:\/\/userswp.io\/documentation\/article\/code-snippets\/how-to-set-a-maximum-length-for-usernames\/","title":{"rendered":"How to Set a Maximum Length for Usernames?"},"content":{"rendered":"\n<p>In UsersWP, you can easily set a max length attribute for usernames, thereby ensuring that usernames cannot be longer than the specified length value.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code Snippet to Set Max Length Attribute for Usernames<\/h2>\n\n\n\n<p>You can use the following code snippet to set the max length attribute for usernames upon registration.&nbsp;&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-blockstrap-blockstrap-widget-alert d-flex align-items-center fade show alert alert-info mb-3\" role=\"alert\"><span class=\"fas fa-info-circle me-2\"><\/span><span class=\"flex-grow-1\">We recommend using the <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\" target=\"_blank\">Code Snippets<\/a> plugin to add snippets to your site.<\/span><\/div>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">add_action( &#039;uwp_template_after&#039;, &#039;uwp_template_after_custom_callback&#039; );\nfunction uwp_template_after_custom_callback($type){\n\tif( &#039;register&#039; == $type  ){\n\t\t?&gt;\n\t\t&lt;script&gt;\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery(&quot;.uwp-registration-form #username&quot;).prop(&#039;maxlength&#039;,&#039;6&#039;);\n\t\t\t});\n\t\t&lt;\/script&gt;\n\t\t&lt;?php\n\t}\n}\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>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.&nbsp;<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In UsersWP, you can easily set a max length attribute for usernames, thereby ensuring that usernames cannot be longer than the specified length value.&nbsp; 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.&nbsp;&nbsp; The above code will limit [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[177,193,194],"article\/categories":[40,7],"class_list":["post-128","gd_place","type-gd_place","status-publish","hentry","gd_place_tags-custom-code","gd_place_tags-username-max-length","gd_place_tags-username-length","gd_placecategory-code-snippets","gd_placecategory-tips-tricks-more"],"_links":{"self":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/comments?post=128"}],"version-history":[{"count":0,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/128\/revisions"}],"wp:attachment":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/media?parent=128"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/tags?post=128"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/categories?post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}