{"id":121,"date":"2025-02-06T12:40:03","date_gmt":"2025-02-06T12:40:03","guid":{"rendered":"https:\/\/documentation.userswp.io\/article\/how-to-force-users-to-login-using-their-email-address\/"},"modified":"2025-03-26T15:39:37","modified_gmt":"2025-03-26T15:39:37","slug":"how-to-force-users-to-login-using-their-email-address","status":"publish","type":"gd_place","link":"https:\/\/userswp.io\/documentation\/article\/code-snippets\/how-to-force-users-to-login-using-their-email-address\/","title":{"rendered":"How to Force Users to Login Using Their Email Address?"},"content":{"rendered":"\n<p>By default, UsersWP allows users to login either via their usernames or using their email addresses. This is in sync with the default WordPress behavior, and works out of the box with no configuration required.&nbsp;<\/p>\n\n\n\n<p>However, if you prefer, you can disable login by username feature, and compel your users to login by entering their email addresses.&nbsp;&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code Snippet to Disable Login Using Usernames<\/h2>\n\n\n\n<p>You can use the following code snippet to make sure that users can only login using their email addresses and not usernames:&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_filter(&#039;uwp_form_input_text_username&#039;, &#039;uwp_form_input_text_username_cb&#039;, 10, 4);\nfunction uwp_form_input_text_username_cb($html, $field, $value, $form_type){ \n\tif(isset($field-&gt;form_type) &amp;&amp; $field-&gt;form_type == &#039;login&#039; &amp;&amp; $field-&gt;htmlvar_name == &#039;username&#039;){\n\t\t$html = aui()-&gt;input(array(\n\t\t    &#039;type&#039;  =&gt;  &#039;email&#039;,\n\t\t    &#039;id&#039;    =&gt;  $field-&gt;htmlvar_name,\n\t\t    &#039;name&#039;    =&gt;  $field-&gt;htmlvar_name,\n\t\t    &#039;placeholder&#039;   =&gt; __(&quot;Email *&quot;, &#039;userswp&#039;),\n\t\t    &#039;title&#039;   =&gt; __(&quot;Email&quot;, &#039;userswp&#039;),\n\t\t    &#039;value&#039; =&gt;  $value,\n\t\t    &#039;required&#039;  =&gt; $field-&gt;is_required,\n\t\t    &#039;validation_text&#039; =&gt; __($field-&gt;required_msg, &#039;userswp&#039;),\n\t\t    &#039;help_text&#039; =&gt; uwp_get_field_description($field),\n\t\t    &#039;label&#039; =&gt; is_admin() ? &#039;&#039; : __(&quot;Email&quot;, &#039;userswp&#039;),\n\t    ));\n    }\n    return $html;\n}\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The above code will prevent users from logging in using their usernames. Instead, users will now need to enter their email addresses in order to login.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By default, UsersWP allows users to login either via their usernames or using their email addresses. This is in sync with the default WordPress behavior, and works out of the box with no configuration required.&nbsp; However, if you prefer, you can disable login by username feature, and compel your users to login by entering their [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[182,183,184,185],"article\/categories":[40,7],"class_list":["post-121","gd_place","type-gd_place","status-publish","hentry","gd_place_tags-login","gd_place_tags-user-login","gd_place_tags-email-login","gd_place_tags-usernames","gd_placecategory-code-snippets","gd_placecategory-tips-tricks-more"],"_links":{"self":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/121","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=121"}],"version-history":[{"count":0,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/121\/revisions"}],"wp:attachment":[{"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/tags?post=121"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/userswp.io\/documentation\/wp-json\/wp\/v2\/article\/categories?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}