WordPress Security: What to Check First and How to Close Every Gap
WordPress troubleshooting

WordPress Security: What to Check First and How to Close Every Gap

WordPress security starts with three simple things: a full backup you can actually restore from, an up-to-date core, plugins and themes, and an admin login protected by a strong password and two-factor authentication. Most of what comes after is hardening specific places, and you do that in order.

In this guide I put the weak points in the order I recommend checking them, and for each one I wrote how to tell there is a problem and how to fix it, with no shortcuts and no unnecessary plugins. Everything is based on the official WordPress documentation, and where a plugin is recommended, it is named.

Before you touch anything, you need a full backup of the files and the database. Any change to wp-config.php, permissions or plugins can bring the site down, and a fresh backup is what brings it back in minutes.

1. Backups: the first check in WordPress security

To know whether there is a problem here, it is enough to answer three questions: when was the last backup taken, where is it stored, and have you ever tried to restore from it? If you have no answer to any of them, this is the first thing to fix.

The official WordPress documentation recommends keeping regular snapshots of the entire installation, including the core files and the database, in a trusted place. A backup stored only on the same server will not help you if the server itself is hit, so it is worth keeping one copy outside it. It is also worth finding out your hosting company’s backup policy, so you know what you can rely on and what you cannot.

2. Updates for the core, plugins and themes

You can see pending updates in Dashboard and then Updates: it shows whether there is an update for WordPress, plugins or themes. The Tools and then Site Health screen also shows alerts like “You have plugins waiting to be updated”.

According to the WordPress documentation, old versions are missing security fixes, so they are exposed to known vulnerabilities. Since WordPress 5.5 you can turn on automatic updates for each plugin separately: go to Plugins and then Installed Plugins, and in the Automatic Updates column click Enable auto-updates. An automatic update saves you from forgetting, but it can also conflict with another plugin. That is why the backup from the previous section is a condition for every update, manual or automatic.

While you are at it, delete plugins and themes that are not active. The Site Health screen lists them under Inactive Plugins and Inactive Themes, and the documentation recommends removing themes you do not plan to use. Code sitting on the server without being used can still be an entry point.

3. Admin login: passwords, usernames and two-factor authentication

On the Users screen, check three things: is there a user named admin, how many users have the Administrator role, and are there users you do not recognize.

WordPress’s guide to protecting against brute force attempts recommends not using the username admin, using strong and unique passwords with a password manager, and turning on two-factor authentication for all admin accounts. Another recommendation there is to keep as few administrators as possible, and give everyone else a role with the minimum permissions they need for daily work. And a user you do not recognize is a reason to check the site in depth, because creation of unauthorized users is listed in the WordPress documentation as one of the clear signs of a hack.

If you do not use XML-RPC (which is mostly used by apps and old external connections), the documentation recommends disabling it, because the xmlrpc.php file is a common target for attacks. And there is another channel people forget: if you have not set up an SPF record for your domain, someone can send emails that look like they came from you, including emails that try to phish login details from your employees.

4. HTTPS and PHP version

You also see this on the Tools and then Site Health screen. On the Info tab there is a line named “Is this site using HTTPS?”, and on the Status tab you will see a message that starts with “Your site is running on an older version of PHP” if the PHP version is old, or “Your site is running on an outdated version of PHP” if it no longer receives security updates.

The WordPress requirements page recommends PHP 8.3 or higher and HTTPS support, and notes that old versions that reached end of life may expose the site to vulnerabilities. You usually change the PHP version in your hosting company’s control panel. Take a backup before the change, and after it go through the site and check that everything works, because an old plugin may not get along with a new version.

To force an encrypted connection for every login and all work in the admin area, add the following line to wp-config.php, above the line that starts with /* That's all, stop editing!:

define( 'FORCE_SSL_ADMIN', true );

5. Hardening wp-config.php and file permissions

The admin menu has two code editors, Theme File Editor and Plugin File Editor. In classic themes they are under Appearance and Plugins, and in block themes under Tools. If the editor opens, whoever gets admin access can edit PHP code directly from the browser, without FTP and without access to the server.

To close this, add this line to wp-config.php, in the same place above the stop editing line:

define( 'DISALLOW_FILE_EDIT', true );

According to the documentation, this adds a layer of protection in case an attacker got access to an account with high permissions. As for file permissions, WordPress’s hardening guide recommends 755 for folders, 644 for files, and 440 or 400 for the wp-config.php file. You change permissions through an FTP program or your hosting file manager. And if you are not sure what each number means on your server, ask your hosting company before you change anything.

There is one more point that is easy to miss. If you once turned on WP_DEBUG_LOG to look for a bug, the log file is saved by default at /wp-content/debug.log. The WordPress documentation warns that a log file in a public place is a security risk, and Site Health will show “Your site is set to log errors to a potentially public file” in that case. When you finish diagnosing, set WP_DEBUG back to false.

6. Firewall and a security plugin: protecting your WordPress site from the outside

If you have no layer that filters traffic before it reaches WordPress, and no way to know that a core file changed, you are working blind.

There are two complementary ways. The first is a firewall at the network or CDN level, such as Cloudflare. The official WordPress guide prefers limiting login attempts at this layer, because it stops the traffic before it loads the server. The second is a security plugin inside WordPress. Wordfence is one of the plugins the official documentation mentions. According to the plugin page, it includes an application firewall, a malware scanner that compares the core files, plugins and themes to the WordPress.org repository, login attempt limiting, two-factor authentication and a CAPTCHA on the login page. Just know that in the free version of Wordfence, firewall rules and scan signatures arrive 30 days later than in the paid version.

After you install a security plugin, check that you can still log in from every device you work from. If the plugin locked you out, you can disable it without access to the admin: use FTP or the file manager to go to the wp-content/plugins folder and rename the plugin’s folder. WordPress will not find it and will turn it off.

When to stop and call an expert

If the site is a store, security does not end with hardening WordPress. There is also the side of the orders themselves, and there it is worth reading the guide on how to prevent credit card fraud on a new ecommerce site. And if you want to look beyond WordPress, at the protection of the whole business, I wrote a separate guide on cybersecurity for a small business.

There are situations where it is no longer hardening but dealing with a hack. The WordPress documentation lists several clear signs of a hack: Google marks the site as dangerous, the hosting company suspended it, visitors report that their antivirus blocks it, or users you did not create appeared. If you see one of these, stop the hardening, back up the site in its current state as it is, and contact a professional.

It is also worth calling an expert when you are not sure what a change in permissions or PHP version will do to the site, when the site is a store where every hour of downtime costs money, or when you have no backup you are sure you can restore from. And if you are also wondering why the site gets no exposure, read why your website is not showing on Google, because a hacked site flagged by Google is one of the reasons.

You can find the full recommendations in the official WordPress hardening guide. And if you tried on your own and did not succeed, or you simply prefer that someone goes through the site for you, talk to me and I will take care of it.

Frequently asked questions

What is the first step in WordPress security?

A full backup of the files and database stored outside the server, followed by an update of the core, plugins and themes. Without a backup, every other fix is riskier.

Is the free version of Wordfence enough?

The free version includes a firewall, a scanner, login attempt limiting and two-factor authentication. The main difference is that firewall rules and scan signatures reach it 30 days later. If you want protection at the network layer too, you can combine it with a CDN firewall.

Should I turn on automatic updates for plugins?

It saves you from forgetting, so it is a good default for most plugins. The condition is that you have a regular backup, because an update can conflict with another plugin. You turn the setting on in Plugins under the Automatic Updates column.

What does DISALLOW_FILE_EDIT do?

This line in wp-config.php turns off the theme and plugin code editors in the admin area. That way, even if someone got access to an admin account, they cannot edit PHP files directly from the browser. You make your own edits through FTP or the file manager.

How do I know if my site has already been hacked?

Clear signs are a Google warning about the site, a suspension by the hosting company, blocking by visitors’ antivirus software, new users you did not create, or foreign content appearing on pages. In that case hardening waits, and you deal with the hack first.

What are the right file permissions in WordPress?

According to the official hardening guide: 755 for folders, 644 for files, and 440 or 400 for wp-config.php. On some servers the settings are different, so check with your hosting company before changing.

Have a project worth talking about?

The call is free, with no commitment 😊