Disable user registration on WordPress login page • Online NC
  • PHP

Disable user registration on WordPress login page

Secure your WordPress site by blocking public user registrations effortlessly.
  • Modifié il y a 5 mois
  • Share

This WordPress code completely disables user registration from the standard login page.

It performs several actions to secure and hide the registration option:

✅  Automatically redirects users to the homepage if they try to access the registration URL (wp-login.php?action=register).

✅  Removes the registration link from the admin bar.

✅ Disables the registration URL by returning an empty string.

✅ Cleans up registration-related messages on the login page.

📌 The goal is to prevent any manual user registrations through the standard WordPress interface, thereby strengthening the site’s security by strictly controlling account creation.

Paste the code into your child theme’s functions.php file.

				
					// File : Disable user registration on WordPress login page.php
function disable_user_registration() {
if ($_SERVER['REQUEST_URI'] == '/wp-login.php?action=register') {
wp_redirect(home_url());
exit();
}
}
add_action('init', 'disable_user_registration');

function remove_register_link($wp_admin_bar) {
$wp_admin_bar->remove_node('register');
}
add_action('admin_bar_menu', 'remove_register_link', 999);

function remove_register_url($url) {
return '';
}
add_filter('register', 'remove_register_url');

function custom_login_message($message) {
if (strpos($message, 'register') !== false) {
$message = '';
}
return $message;
}
add_filter('login_message', 'custom_login_message');


				
			
  • Kevin Ekelmans Presario