Remove register link from WordPress wp-login.php

This post is more than 10 years old.

I recently had to enable user registrations on a WordPress multisite, so that shops on that site could allow customers to register. I don’t want users to register any other way, only through specific applications on specific subsites. Enabling user registrations adds a “register” link to the wp-login.php script page. That invites trouble!

So, here’s a little script to remove that little link. It doesn’t stop user registrations via any other means, it only prevents registrations from the wp-login.php script. My shops still let users register, and Gravity Forms User Registration still functions. You can download the gist if you prefer.

/**
* remove the register link from the wp-login.php script
*/
add_filter('option_users_can_register', function($value) {
    $script = basename(parse_url($_SERVER['SCRIPT_NAME'], PHP_URL_PATH));

    if ($script == 'wp-login.php') {
        $value = false;
    }

    return $value;
});

Job is done, just not on wp-login.php