How to Limit Login Attempts in WordPress for Better Security

Limit login attempts in WordPress security tutorial

Brute-force attacks are one of the most common threats to WordPress sites, where hackers use automated tools to guess login credentials repeatedly. Limiting login attempts is a simple yet effective way to block these attacks, reducing the risk of unauthorized access and keeping your site secure. In 2026, with cyber threats more sophisticated, this measure is essential for protecting user data and maintaining SEO rankings. At Cope Business, we implement login protections routinely during our technical SEO audit services to safeguard client sites from breaches. This guide covers two reliable methods to limit login attempts—using plugins for ease or custom code for control.
Whether you’re a beginner or managing a high-traffic site, adding this layer of security takes minutes and provides peace of mind.

Why Limit Login Attempts in WordPress?

Default WordPress allows unlimited login tries, making it vulnerable to bots that can test thousands of passwords per hour. Limiting attempts:

  • Blocks brute-force attacks by locking out IPs after failed tries.
  • Reduces server load from malicious traffic.
  • Improves overall security, complementing measures like 2FA.
  • Helps comply with privacy laws by protecting user accounts.

Without it, a successful hack could lead to data theft, spam injections, or site defacement—damaging your reputation and SEO.

Method 1: Using a Plugin (Recommended for Beginners)

Plugins make setup effortless with automatic blocking and customizable rules.

Recommended Plugin: Limit Login Attempts Reloaded (Free)

This lightweight plugin is highly rated and actively maintained.

Steps to Set Up

  1. Install and activate Limit Login Attempts Reloaded from Plugins > Add New.
  2. Go to Settings > Limit Login Attempts to configure.
  3. Set the number of failed attempts before lockout (default: 4).
  4. Choose lockout duration (e.g., 20 minutes for first offense, longer for repeats).
  5. Enable IP whitelisting for your own access if needed.
  6. Turn on email notifications for lockouts.
  7. Save changes—the plugin starts protecting immediately.

Advanced Options: Block countries or IPs, customize messages, and view logs in the dashboard.

Alternative: Login LockDown (free) or Wordfence (free with premium upgrades for more features).

Benefits: No coding required, detailed logs, and easy rollback if issues arise.

Method 2: Using Custom Code (For Advanced Users)

For more control or a lightweight solution, add code to limit attempts manually.

Steps to Implement

  • Install WPCode (free) for safe code insertion.
  • Go to Code Snippets > Add Snippet and create a new one.
  • Paste this PHP code:
PHPfunction wpb_login_failed() { $login_attempt = get_option( 'wpb_login_attempts' ); update_option( 'wpb_login_attempts', $login_attempt + 1 ); } add_action( 'wp_login_failed', 'wpb_login_failed' ); function wpb_verify_username_password( $user, $username, $password ) { $login_attempt = get_option( 'wpb_login_attempts' ); if ( $login_attempt > 5 ) { return new WP_Error( 'login_failed', __( "You have exceeded login attempts. Please try after 20 minutes." ) ); } return $user; } add_filter( 'authenticate', 'wpb_verify_username_password', 1, 3 ); function wpb_login_success() { update_option( 'wpb_login_attempts', 0 ); } add_action( 'wp_login', 'wpb_login_success' );
  • Adjust the attempt limit (5) and lockout message as needed.
  • Activate the snippet—test by attempting failed logins.

Tips: This code locks after 5 fails for 20 minutes (customize the delay). For IP tracking, use a plugin instead.

Best Practices After Setup

  • Combine with 2FA: Add two-factor authentication via plugins like WP 2FA for extra protection.
  • Monitor Logs: Review failed attempts in your plugin dashboard or server logs.
  • Enable CAPTCHA: Add reCAPTCHA to login forms to block bots.
  • Change Login URL: Use WPS Hide Login to obscure wp-login.php.
  • Performance Check: Ensure the solution doesn’t slow your site—test with GTmetrix.

Regularly review and update your security measures to stay ahead of threats.

Final Thoughts

Limiting login attempts is a foundational security step that protects your WordPress site from brute-force risks. Start with a plugin for simplicity, or use code for customization—either way, it’s a quick win for safety.

A secure site supports better performance and SEO.

Need help implementing login protections or a full security audit? Contact Cope Business for a free technical SEO consultation—we’ll fortify your site against common threats.

Was this article helpful?
YesNo