Custom login URL generator
Hide wp-login.php from the bots that scan for it by default.
Genuinely free. No sign-up, no email, no limits, no cookies. We don't store the URL you analyse.
<?php
// Custom login URL: /secure-login instead of /wp-login.php
add_action( 'init', function () {
add_rewrite_rule( '^secure-login/?$', 'wp-login.php', 'top' );
} );
// Rewrite the login form's own links (wp_login_url, wp_logout_url, etc.) to the new slug
add_filter( 'site_url', function ( $url, $path, $scheme, $blog_id ) {
if ( strpos( (string) $path, 'wp-login.php' ) === false ) {
return $url;
}
return str_replace( 'wp-login.php', 'secure-login', $url );
}, 10, 4 );
// Block direct access to wp-login.php and wp-admin for logged-out visitors
add_action( 'init', function () {
global $pagenow;
$is_login_request = 'wp-login.php' === $pagenow
&& ! isset( $_GET['loggedout'] )
&& strpos( $_SERVER['REQUEST_URI'] ?? '', 'secure-login' ) === false;
$is_admin_request = is_admin() && ! wp_doing_ajax() && ! is_user_logged_in();
if ( $is_login_request || $is_admin_request ) {
wp_die( 'Not found', 'Not found', array( 'response' => 404 ) );
}
} );
// After activating: go to Settings > Permalinks and click "Save Changes" once,
// otherwise /secure-login returns a 404 (the rewrite rule needs flushing).What it's for
wp-login.php is the first address every automated scanner tries on a WordPress site. Without changing how the site works, moving the login to an address only you know eliminates the vast majority of automated login attempts. Test this in staging before applying it to production: a mistake here can lock you out of the dashboard.
Frequently asked questions
›Can this snippet lock me out of my own site?
Yes, if you install it without first re-saving permalinks (Settings > Permalinks > Save Changes, to activate the new rewrite rule) or if you forget the new address. Test it on a staging copy of the site before going to production, and keep the new slug written down somewhere.