WordPress

Password protect WordPress wp-admin and wp-login

  1. Log in to cPanel.
  2. Click Directory Privacy
  3. Click the folder icon next to public_html
  4. Click wp-admin
  5. Check Password protect this directory
  6. Enter WordPress Admin for Name then click Save
  7. Click Go Back
  8. Under Create User enter a Username, click Password Generator to create a strong password.
  9. Save the password for later, click I have copied this password in a safe place and click Use Password
  10. Click Save at the bottom of the page
  11. Click Search Features and type File Manager. Click File Manager
  12. Open your public_html directory
  13. Open wp-admin
  14. Select .htaccess and click Edit
  15. At the top of the file enter the code below:
    ErrorDocument 401 "Unauthorized"
    ErrorDocument 403 "Forbidden"
    
    # Allow admin-ajax.php access
    <files admin-ajax.php>
    Order allow,deny
    Allow from all
    Satisfy any
    </files>
  16. Click Save Changes

  17. Click Close
  18. Click public_html on the left
  19. Select .htaccess and click Edit
  20. At the top of the file enter the code below
    ErrorDocument 401 "Unauthorized"
    ErrorDocument 403 "Forbidden"
    
    <filesmatch "wp-login.php">
    AuthType Basic
    AuthName "WordPress Admin"
    AuthUserFile "/home/example/.htpasswds/public_html/wp-admin/passwd"
    require valid-user
    </filesmatch>

    Note: Replace *example* with your cPanel username
  21. Click Save Changes

Open your WordPress Dashboard. You should see a prompt for a username and password. Enter your username and password you created earlier to login.

Was this guide helpful?

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London