You're right. Removing suspicious files doesn't always solve the underlying problem.
If a website gets infected repeatedly, there's a good chance that the original entry point is still available or some malicious code has been left behind.
For example, an outdated plugin might contain a vulnerability that attackers can exploit again. A compromised administrator account could also allow someone to reinstall malicious code.
I'd recommend approaching this as a complete security cleanup rather than simply deleting infected files.
Start by identifying how the attacker gained access. Review security logs, recently modified files and suspicious administrator accounts.
Then:
- Update WordPress, plugins and themes to secure versions.
- Remove unused or abandoned plugins and themes.
- Review administrator accounts and revoke unfamiliar access.
- Scan the database for suspicious injected content.
- Check
.htaccess, wp-config.php and other important configuration files.
- Change all relevant passwords and regenerate WordPress security salts.
- Scan other websites under the same hosting account.
If you're unsure whether the website is completely clean, restoring from a verified clean backup may be safer than manually removing individual infected files.
Also, ask your hosting provider to investigate whether the infection is isolated to your account or related to a wider server-level issue.
The biggest lesson is that malware removal and vulnerability prevention are two different jobs. You need to do both to prevent the same infection from returning.