WordPress security basics to protect your site from malware

WordPress Security Basics: How to Protect Your Site From Malware

Most hacked WordPress sites are not targeted by a person. They are found by automated bots scanning thousands of sites for weak passwords, outdated plugins and known vulnerabilities. The good news is that a handful of basic habits blocks the vast majority of these attacks. Here are the WordPress security basics I apply to every site I manage.

Signs your WordPress site may already be infected

  • Visitors are redirected to spam, gambling or fake prize pages
  • Google shows “This site may be hacked” in search results or Chrome shows a red warning
  • New admin users you did not create
  • Unknown files in wp-content/uploads or the site root, especially PHP files
  • Your host suspends the account or warns about sending spam email
  • Sudden drops in traffic or strange pages appearing in Google Search Console

If you see any of these, skip to the cleanup section below before hardening the site.

1. Keep WordPress, plugins and themes updated

Outdated plugins are the most common way attackers get in. Apply security updates quickly and follow a safe routine for bigger releases. My guide on how to update WordPress plugins safely walks through the full process, including backups and testing.

Also delete plugins and themes you are not using. A deactivated plugin can still be exploited if its files are on the server.

2. Lock down logins

  • Use strong, unique passwords for every admin account, stored in a password manager
  • Turn on two factor authentication for all administrators
  • Limit login attempts with a plugin such as Limit Login Attempts Reloaded to stop brute force attacks
  • Remove old users and give each person the lowest role they need. Not everyone needs to be an Administrator
  • Avoid the username “admin”, which is the first name bots try

3. Back up automatically and off site

Backups are your safety net. Schedule daily backups of files and the database, keep at least two weeks of history, and store copies somewhere other than the same server (cloud storage or your host’s separate backup system). A backup that sits on an infected server can be infected too.

4. Harden the server and WordPress settings

  • Run a supported PHP version (your host’s control panel usually lets you switch)
  • Force HTTPS across the whole site with a valid SSL certificate
  • Disable the built in file editor by adding define('DISALLOW_FILE_EDIT', true); to wp-config.php
  • Set sensible file permissions: 644 for files and 755 for folders
  • Block PHP execution in the uploads folder
  • Use a web application firewall, either through your host, Cloudflare or a security plugin

5. Scan and monitor regularly

Install a security plugin such as Wordfence or Solid Security to scan files for malware and alert you to changes. Connect the site to Google Search Console so you are notified if Google detects a security issue, and check it monthly.

How to clean up a hacked WordPress site

  1. Take a backup of the infected site so nothing is lost while you work
  2. Put the site in maintenance mode if visitors are being redirected
  3. Change all passwords: WordPress admins, hosting, cPanel, FTP and the database
  4. Replace WordPress core files with fresh copies and reinstall plugins and themes from the official sources
  5. Scan for and remove malicious files, unknown admin users and injected code in the database
  6. Update everything, then apply the hardening steps above
  7. Request a review in Google Search Console if Google flagged the site

Reinfection is common when the original entry point is not closed, so finding the vulnerable plugin or weak password matters as much as removing the malware.

Frequently asked questions

Is WordPress secure?

Yes. WordPress core is well maintained and secure. Most hacks come from outdated plugins and themes, weak passwords and poor hosting, all of which you can control.

Do I need a security plugin?

A security plugin is a good idea for most sites because it adds malware scanning, login protection and alerts. It works best alongside updates, strong passwords and backups, not instead of them.

How do I know if my WordPress site has malware?

Common signs include spam redirects, browser or Google warnings, unknown admin users and unfamiliar PHP files. A malware scanner and Google Search Console’s security issues report can confirm it.

Why does my site keep getting hacked again?

Usually because the entry point was not fixed. If a vulnerable plugin, a backdoor file or a compromised password remains, attackers can return even after the visible malware is removed.

Dealing with a hacked or vulnerable WordPress site? Contact me for help with cleanup and ongoing maintenance, or read more web development articles.