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 working with clients
Foreign Trade Website Building, I have become accustomed to using
Code Snippetsthis plugin to manage custom code, so this tutorial also uses this method. 1. Install
Code Snippets2. Create a new Code, copy the code below, and save it.

// 移除空邮件地址的提示
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) {
?>
3. After saving, the email field will no longer be mandatory when users register on the frontend or when adding users in the backend.
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.