Snippet

How to Disable New User Registrations in WordPress Easily

How to disable user registration in wordpressWordpress disable new user registrationStop user registration wordpressTurn off user registration wordpressWordpress prevent new user sign upDisable wordpress registration formBlock user registration wordpressWordpress no new user registrationWordpress stop registrationHow to turn off registration in wordpress

Explanation

If you want to stop new users from signing up on your WordPress site, here's a simple way to do it.

Disable Registration Option:

  • The code automatically turns off the "Anyone can register" setting in your WordPress General Settings. This means no new users can sign up.

Remove Registration Link:

  • It also removes the registration link from the login page, so visitors won't see an option to register.

Redirect Registration Page:

  • If someone tries to access the registration page directly, they'll be redirected to your homepage instead.

With these changes, your site will no longer allow new user registrations, keeping your community exclusive or private as needed.

Code

1// Function to disable new user registration in WordPress 2function wp_dudecom_disable_user_registration() { 3 // Remove the 'Anyone can register' option from the General Settings 4 update_option('users_can_register', 0); 5} 6 7// Hook the function to 'init' to ensure it runs on every page load 8add_action('init', 'wp_dudecom_disable_user_registration'); 9 10// Function to remove the registration link from the login form 11function wp_dudecom_remove_register_link($link) { 12 // Check if the link is for registration and return an empty string if true 13 if (strpos($link, 'wp-login.php?action=register') !== false) { 14 return ''; 15 } 16 return $link; 17} 18 19// Hook the function to 'register' filter to modify the registration link 20add_filter('register', 'wp_dudecom_remove_register_link'); 21 22// Function to redirect users trying to access the registration page 23function wp_dudecom_redirect_registration_page() { 24 // Check if the current page is the registration page 25 if (isset($_GET['action']) && $_GET['action'] === 'register') { 26 // Redirect to the home page 27 wp_redirect(home_url()); 28 exit; 29 } 30} 31 32// Hook the function to 'login_init' to check for registration page access 33add_action('login_init', 'wp_dudecom_redirect_registration_page');

Instructions

File Location: Add the following code to your theme's functions.php file or a custom plugin file.

Prerequisites:

  • Ensure you have access to your WordPress site's file system, either via FTP or a file manager.
  • Backup your site before making changes to the code.

Implementation Steps:

  1. Access your WordPress site's file system using FTP or a file manager.
  2. Navigate to the wp-content/themes/your-active-theme/ directory.
  3. Open the functions.php file in a text editor.
  4. Copy and paste the provided code snippet at the end of the functions.php file.
  5. Save the changes and upload the file back to the server if using FTP.
  6. Clear your browser cache and test the changes by attempting to register a new user on your site.

By following these steps, you will successfully disable new user registrations on your WordPress site. If you need further assistance or want to explore more advanced functionalities, consider reaching out to wp-dude.com for expert help.