how to make email optional while user registration using default wordpress form

Question

I wonder if there is any way to make email an optional field while registering using default form. So that those who don’t know mail may leave it blank.

I got code from stackexchange but that doesn’t seems to work.I added code to functions.php under theme folder.

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');
}

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();

    <?php if (isset($form_type) && $form_type === 'add-new-user') : ?>
        jQuery ('#send_user_notification') .removeAttr('checked');
    <?php endif; ?>
    </script>
    <?php
}

Any help is appreciated.Thanks in advance

Reference

0
David Becckam 2 months 0 Answers 15 views 0

Leave an answer