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
  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

    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.