🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

WordPress Remove Mandatory Email Field for New User Registration (Registration Without Email/Email Not Required)

Websites built with WordPress support user registration for e-commerce sites. By default, registration requires users to fill in an email address, which is mandatory. However, some websites have special circumstances and may not need to enforce email entry. Therefore, we can use the following code to change the mandatory email field to an optional item. The specific method is as follows: Recently, when building foreign trade websites for clientsForeign Trade Website BuildingI have become accustomed to usingCode Snippetsthis plugin to manage custom code, so this tutorial also uses this method. 1. InstallCode Snippets2. Create a new Code, copy the following code, and then save it.WordPress移除用户新注册时邮件必填选项
// 移除空邮件地址的提示
add_action('user_profile_update_errors', 'my_user_profile_update_errors', 10, 3 );
function my_user_profile_update_errors($errors, $update, $user) {
$errors->remove('empty_email');
}

// 这将删除电子邮件输入所需的javascript验证
// 还将删除标签中的(必填)提示
// https://blog.naibabiji.com/skill/users-without-email-in-wordpress.html
add_action('user_new_form', 'my_user_new_form', 10, 1);
add_action('show_user_profile', 'my_user_new_form', 10, 1);
add_action('edit_user_profile', 'my_user_new_form', 10, 1);
function my_user_new_form($form_type) {
?>
<script type="text/javascript">
jQuery('#email').closest('tr').removeClass('form-required').find('.description').remove();
// Uncheck send new user email option by default
<?php if (isset($form_type) && $form_type === 'add-new-user') : ?>
jQuery('#send_user_notification').removeAttr('checked');
<?php endif; ?>
</script>
<?php
}
3. After saving, the email field will no longer be mandatory when users register on the frontend or when adding users in the backend.WordPress移除用户新注册时邮件必填选项

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step.

「Naibabiji WordPress Website Building Coaching Service」—From choosing a domain and buying hosting, to installing a Theme and publishing content, I「ll coach you through every step, helping you avoid detours and reach your goal directly.

👉 Learn about the Website Building Coaching Service
🔒

Comments are closed

The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.

×
二维码

Scan QR Code to Follow

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: