Remove register link from WordPress wp-login.php

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

Facebooktwittergoogle_plusredditlinkedinmailFacebooktwittergoogle_plusredditlinkedinmail
  • Casey Rollins

    This didn’t work for me. Not sure I did anything wrong. I actually just uploaded the plugin, activated it, and —- the register link was still there on wp-login.php.

    • Is your login page called “wp-login.php”? I’ve tested this on single installs and multisite, works on both.

  • mcpace

    Thank you! Exactly what I needed.

  • Thank you for the snippet.

  • Jasmine Green

    Great! Thank you. Just what I needed to add.

  • Κώστας

    Guys where should I put this code? I use a child theme..