Here’s How Hackers Can Find your WordPress Username

Last updated on

So you’ve taken pains to hide your WordPress login and admin screens from hackers. You’ve changed your default usernames, and removed all mention of them from your theme. You’re safe right? There’s no way that hackers can find your login pages, let alone your usernames. Wrong! Unless you take precautions, here’s how hackers can find your WordPress username with ease. And not just yours – those of everyone on the site.

Two Methods:

Method 1: Using /?author=1 Query Parameter

One day, I had just set up a new blog and thought I’d hidden my admin areas pretty well. To my surprise, my security plugins started sending me lockout notices. This means that not only were hackers able to find my login page, they were able to guess my WordPress username as well! I opened up my raw access logs in cPanel, and found this:


Apparently, hackers can find your username in WordPress by appending the query /?author=1! You can see in the screenshot above, that my server immediately returned the author page – which of course, revealed the username. So forget about making your username difficult to guess. It’s right out there in the open!

Here’s how it looks. First, type in your blog name and type /?author=1 after the URL like this:


This will immediately redirect to your author page like so:

Hackers can find your WordPress Username

Some experts claim that exposing WordPress usernames is not a security risk. According to them, creating a strong password and using two factor authentication is the right way to go about it. But I say there’s nothing wrong in hiding as much information as possible from hackers. Maybe if someone is truly determined to know my username, they can. But that doesn’t mean I have to make it easy for them! I want potential attackers to work to break into my site. Hopefully, this will deter 90% of them.

If hackers don’t know your username, they won’t spam your site trying to guess your password. This means less load on your server. I’ve been brought down once before by hackers DDoS’ing my login page. I don’t want to risk that again.

So how do we close this loophole? There are two ways to prevent WordPress from revealing your author name via the parameter hack.

Fix 1: Modifying .htaccess

This is my preferred technique because it’s much faster than the alternative. By creating a simple .htaccess rule, you can immediately block all attempts to access your WordPress username via the ?author parameter. If you have access to it, open the hidden “.htacces” file in the root directory of your WordPress installation, and paste in the following code at the end:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
RewriteCond %{QUERY_STRING} author=\d
RewriteRule ^ /? [L,R=301]

Here’s what the WordPress .htaccess looks with the above code added on:


These rules check to see that you’re not in the admin area, and whether or not someone is attempting to access the “author” query parameter. If the conditions are met, it simply redirects back to the WordPress homepage. Problem solved!

After implementing this code in my .htaccess, the raw access log entry looks like this:


So even though someone has attempted to find out my username by typing “/?author=1”, the server smartly sends back the homepage of my blog. This is an extremely fast process, and hardly uses any server resources. So it’s the efficient and preferred way.

But what if you can’t make changes to .htaccess? Then the second method is the one for you.

Fix 2: Adding a Code Snippet to WordPress

The second method is to add a code snippet to WordPress that accomplishes the same. If you don’t know how, read my earlier step by step tutorial on how to do this. Here is the code you need to paste into your custom plugin or functions.php:

function redirect_to_home_if_author_parameter() {

	$is_author_set = get_query_var( 'author', '' );
	if ( $is_author_set != '' && !is_admin()) {
		wp_redirect( home_url(), 301 );
add_action( 'template_redirect', 'redirect_to_home_if_author_parameter' );

Like the .htaccess code, this does exactly the same thing. It checks to see if you’re not in the admin area, and whether or not someone is trying to access the author name via the “?author” parameter. If so, it redirects back to the home page.

The difference is that this executes at the WordPress level, and is therefore slightly more inefficient than the first method. But if you don’t have access to .htaccess, it’s the only other way. Checking your access logs will reveal the exact same thing regardless of which method you choose.

So while some might deny that revealing usernames is a security threat, my principle is that the harder you make it for someone to snoop around your website, the better. And if you want to prevent brute force attacks, and to prevent hackers from finding your WordPress username, one of these two snippets of code will do the trick!

If you’re looking at really getting the most out of WordPress, you should consider specialized hosting. Different companies have different deals, and you can view the comparisons of the WordPress hosting prices at one glance.

Method 2: Using WordPress JSON REST Endpoints

Visit the following URL on your WordPress site:


Replace [yoursite] with your site name. You should get something like this:

Get the Username via wp-json

That’s your WordPress username in plain sight! This is because WordPress exposes certain REST APIs by default and this allows anyone to enumerate the users via JSON.

Fix: Disable via Code

Fortunately, we can just disable these endpoints via this simple code snippet:

function disable_rest_endpoints ( $endpoints ) {
    if ( isset( $endpoints['/wp/v2/users'] ) ) {
        unset( $endpoints['/wp/v2/users'] );
    if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {
        unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
    return $endpoints;
add_filter( 'rest_endpoints', 'disable_rest_endpoints');

After you’ve saved your changes, users will be met with this message instead:

WordPress Rest Endpoint JSON Disabled

Blocking these two methods should make it hard for hackers to get a hold of your username!

About Bhagwad Park

I've been writing about web hosting and WordPress tutorials since 2008. I also create tutorials on Linux server administration, and have a ton of experience with web hosting products. Contact me via e-mail!


  1. Thank you for writing about this topic. I think I might have found another option:

    Install the plugin “Edit Author Slug”, then enter a new author slug (different to your username) in your profile. You can also set a 301 Redirect from the old version to the new one by entering the following in .htaccess :

    RewriteEngine On
    Redirect 301 /author/username-that-you-want-hidden/

    With this method, the author’s archive page is still usable.


  2. William Wallace says

    Thanks for that!!! So many and “little” things you have to think about


  3. Hey! I now thks is somewhat off topic but I was wondering if you knew where I could find a casptcha plugin for
    myy coomment form? I’m using the same bloog platform as yours and I’m having
    difficulty finding one? Thanks a lot!


  4. Thanks for this, great solution . I was searching for a solution because I have several hacking attempts doing exactly this. .htaccess solution worked a treat I really wanted to do this server side. 🙂


  5. hi,

    as third attempt its possible to use the “author.php” and put just the redirect code in.

    that way when have to add author profile pages later on it will be easy to find and replace.


  6. Perhaps a stupid question, but does it matter if that piece of code (or any piece of code?) for the .htaccess is inside or outside of the tags?

    example: If I append that BEFORE the will it still work?


  7. Yikes! There’s a vulnerability I hadn’t thought of! Especially when combined with the xmlrpc.prg file that allows multiple requests per request. Say, a xmlpc.prg that has parameters to try a rainbow table of passwords to login. And then continual login attempts…

    Yikes again!

    This is going in all the sites I manage right now! (And is why there is a phony email address in this comment – I need some time to get this on all my sites.)


  8. Glad you found it useful!


  9. This is a great tweak, thanks!
    I use wordfence on all the websites that I maintain and on every unsuccessful login attempt it fires off an email to me and blocks the ip of the user for 4hrs. I bet you can guess how many emails I get just from this alone!
    This tweak should make it much more interesting for these ‘users’.


  10. I have started to get notifications recently that hackers are able to figure out my username. Before, they try to login with Admin or other similar usernames, but now they are able to guess the exact username few minutes after I change it. I tried your method but my website returns a 404 page when you add /?author=1 to the URL.

    So my question, is there another way hackers can figure out my username?


  11. I added the `?author=1` after my Blog’s URL, and didn’t get the Author name. Does that necessarily mean that my site is protected from this, or maybe I’m missing something…?


  12. If you use Anti-Malware from GOTMLS.NET plugin, it automatically blocks that query.


  13. I checked both of your methods and found that my site was vulnerable to both. Fixed it with your solutions, now working properly and without the vulnerabilities. Thanks!


  14. Hello, for Method 2: (Using WordPress JSON REST Endpoints)
    Where exactly do we add this code snippet ?
    Thank you


  15. Jacobus Lavooij says

    Thanks man. Really appreciated. I was going nuts. My site was online for about an hour when the attacks started and I was flabbergasted that they knew my admin name (which, clearly, wasn’t Admin). I couldn’t get it to work with the custom plugin (the edit button didn’t appear, even with all plugins deactivated) but I am now using the Code Snippets plugin…


  16. Hey,

    Neither method one or method two shows my username, in method two I this: {“code”:”rest_user_invalid_id”,”message”:”Invalid user ID.”,”data”:{“status”:404}}’.

    People are still able to guess my username though, how? (my site isn’t even live!)


  17. Hi!
    I added the below code to the .htaccess file in the WordPress root folder, but it didn’t help out. Still able to the the /?author=1 and it responded with the user name.

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
    RewriteCond %{QUERY_STRING} author=\d
    RewriteRule ^ /? [L,R=301]


    • Remove the second line then it worked for me. Some say about using the author.php how do they use that? Can someone show an example of fixing that way please. Thanks


  18. Thank you very much. It was very annoying to see unauthorized login attempts a few hours after I did reset my admin username and password – again! This is not even covered by many security suite plugins, that are overly bloated, as far as could test them.

    Cheers, corumeach


  19. I think you should add the redirect also to the author permalink otherwise a hacker can still access the author page and try and guess a login name. A valid user will return a 200 response and invalid 404.

    eg will return a 200 response if the username exists.


    • Thanks for the idea! Are you sure about this? If you post a test URL, I can evaluate the response headers and see how to proceed further…


      • I put in his code and it got me to a page with some unedited page on my site but with a 404 below that. However, hitting any menu item took me to the maintenance screen (which is correct for now)


Speak Your Mind