fail2ban to prevent Brute Force Attacks on WordPress?

[pedantic mode] fail2ban obviously do not prevent attacks. The only way to prevent attacks is by sending the people that originate them to jail or give them some other incentive to stop.

More to the point, fail2ban suffers from having only a single point of reference while attackers control many sources. To have an effective brute force attack detection you probably need to gather info from many servers and accumulate information about possible attackers, otherwise you will have to set such a long attack retention tracking that you will increase the possibility of locking yourself out.

The right way to avoid being “broken into” is by having strong password, and possibly to change the login url.

But if you still want the fuzzy warm feeling of creating a security theater by integrating with fal2ban, just use one of the plugins that do that. There is zero point in reinventing the wheel as there are probably many small details to take care of, and it is a total waste of time if you are doing it as a “one off” thing.