Key points
?author=1, the REST API, the users sitemap and login error messages all reveal usernames.- About twenty lines in a must-use plugin close them without breaking the block editor.
- This cuts noise, it is not a defence on its own: strong passwords and two-factor authentication still matter most.
Clients regularly show us login logs full of attempts against their real username rather than “admin”, and ask how the attackers knew it. Nobody broke in. A default WordPress install simply publishes its authors’ login names in several places. This is how we find and close those leaks on the sites we look after.
Where usernames leak
/?author=1redirects to/author/username/, because the author slug (user_nicename) defaults to the login name./wp-json/wp/v2/userslists, to anyone, every user who has published at least one post, slug included./wp-sitemap-users-1.xml, the core sitemap, has one URL per author, so the same slug again.- The login form tells you whether the username or the password was wrong.
Open those three URLs in a private window. If you end up looking at your own login name, this applies to you.
The code we ship
We put it in a small must-use plugin in wp-content/mu-plugins/ rather than in the theme, so it survives a redesign.
// Stop ?author=N scans before WordPress redirects to /author/login/
add_action( 'template_redirect', function () {
if ( isset( $_GET['author'] ) && ! is_user_logged_in() ) {
wp_safe_redirect( home_url( '/' ), 301 );
exit;
}
}, 1 ); // priority 1: runs before redirect_canonical()
Priority 1 matters: the revealing redirect comes from redirect_canonical(), which sits on the same hook at priority 10. For the REST API, the trap is blocking everyone.
// Hide the users endpoints from anonymous visitors only
add_filter( 'rest_pre_dispatch', function ( $result, $server, $request ) {
if ( str_starts_with( $request->get_route(), '/wp/v2/users' )
&& ! current_user_can( 'edit_posts' ) ) {
return new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), [ 'status' => 401 ] );
}
return $result;
}, 10, 3 );
// Remove the users sitemap (wp-sitemap-users-1.xml)
add_filter( 'wp_sitemaps_add_provider', function ( $provider, $name ) {
return 'users' === $name ? false : $provider;
}, 10, 2 );
// Same message whether the username or the password is wrong
add_filter( 'login_errors', function () {
return __( 'Incorrect username or password.' );
} );
On one project, an early version that removed /wp/v2/users outright emptied the author dropdown in the block editor, which reads that exact endpoint. Checking the edit_posts capability lets logged-in writers through and turns anonymous visitors away.
Fixing slugs that are already public
Closing the leaks does nothing for author archives search engines have already seen. If the site shows author pages, we give each author a public slug that differs from the login, using WP-CLI:
wp user list --fields=ID,user_login,user_nicename,display_name
wp user update 3 --user_nicename=editorial-team --display_name="Editorial team"
Old /author/… URLs will then return a 404, so add a redirect if they ever got traffic.
What this does not replace
Hiding usernames quietens the bots, but a username was never a secret. Real protection is a long, unique password, two-factor authentication for administrators, login rate limiting and, if nothing uses it, disabling xmlrpc.php, which happily accepts password guesses too.
FAQ
Doesn’t my security plugin already handle this?
Often only partly. Plenty of them block ?author= and leave the REST API or the sitemap open. Test the three URLs after installing it instead of trusting a ticked checkbox.
Will this hurt SEO?
No, as long as author pages stay reachable through their normal links. Only the users sitemap goes away, and it rarely adds anything to a business site.
Want to know what your WordPress site really exposes? We run security reviews and provide ongoing WordPress maintenance, fixes included.



