Skip to main content
WordPress

How to Secure a WordPress Website: Step-by-Step Guide

Published
Updated
12 min read

You secure a WordPress website by keeping the software updated, keeping a backup you have restored once, and making it hard for a stranger to log in. Do those three before you chase obscure settings. The rest of this guide is the detail: two-factor login, a firewall, HTTPS, user roles, the login screen, hosting, a few lines in the configuration file, and what to do if the site is already compromised.

You need a WordPress login and access to your host. If a step needs the server, ask the host. Back up before you edit files, and do not paste commands you do not understand.

Contents

  1. Keep WordPress core, themes, and plugins updated
  2. Back up the site, and test a restore
  3. Use a strong unique password and two-factor authentication
  4. Add a security plugin or a firewall
  5. Serve the whole site over HTTPS
  6. Give each person the least access they need
  7. Make the login harder to guess
  8. Choose hosting that handles the basics
  9. Harden a few settings
  10. What to do if the site is hacked
  11. Security checklist

Keep WordPress core, themes, and plugins updated

Out-of-date software is the ordinary way into a WordPress site. An old plugin, theme, or copy of WordPress can have a known flaw that works on any site still running that version.

Open Dashboard → Updates and install what is waiting. On the Plugins and Themes screens, use Enable auto-updates for items you still use. Leave WordPress able to update itself, unless you apply updates by hand the same day and then check the site. After an update, open the homepage, a form, and the checkout if you have a shop.

The Hardening WordPress guide says to delete plugins you are not using. A deactivated plugin is still code on the server. Delete unused themes too, and keep one default WordPress theme so you can switch to it if the active theme fails.

Install plugins and themes only from a source you can name, and only if they are still updated. Start in the WordPress.org plugin directory. Check the last update and whether it supports a current WordPress version. Do not install a zip that arrived by email.

Back up the site, and test a restore

A backup is what lets you undo a bad update or a hack. The hardening guide says to back up regularly, including the database, and links to backing up the database.

A useful backup includes the files (themes, plugins, uploads) and the database (posts, pages, users, settings). It runs on a schedule you can see, and a copy lives somewhere other than the same server. If the server or the account is lost, a backup folder next to the site can go with it.

Restore one backup, on a staging copy or with your host, and check that the pages and the login work. A backup you have never restored is a hope.

A simple way to count copies is the 3-2-1 rule: three copies, on two kinds of storage, with one copy off the server. The live site, the host's backup, and a download can be those three. A WordPress backup contains user accounts and form entries, so restrict who can download it.

Use a strong unique password and two-factor authentication

Someone who logs in as an administrator can install code on the server. Use a long password you do not reuse for email or any other site. A password manager can create and store it. WordPress shows a strength meter when you change a password. Avoid your name, the company, the site name, a dictionary word, or a short or single-type password. The hardening guide lists those as things to avoid.

Change it under Users → Profile, and have every administrator do the same. Also change the host, database, and SFTP passwords. Those are separate logins.

WordPress does not include a second login step in core. The Two Factor plugin, published by WordPress.org, adds one. Each person enables it on their own profile. The plugin recommends an authenticator app, and it can generate backup codes so a lost phone is not a lockout. Store those codes off the server, and turn the feature on for every administrator.

Add a security plugin or a firewall

A security plugin runs inside WordPress. Depending on the one you choose, it may watch for file changes, slow repeated logins, or warn you about known problems in installed software. A web application firewall filters requests before WordPress fully handles them. Some are plugins, some run on the server, and some are a service in front of the host.

The hardening guide names Wordfence as a plugin that filters attacks as WordPress loads, and Sucuri as a service that can sit in front of the site. It also names iThemes Security, which WordPress.org now lists as Solid Security, formerly iThemes Security. Those are examples, not a ranking. This guide does not compare prices or promise a feature a listing does not spell out. Install one tool you understand. Two firewalls at once are harder to debug than one, and neither replaces updates or backups.

Serve the whole site over HTTPS

HTTPS encrypts traffic between the visitor and the site, including the password typed at login. The hardening guide says administration should use an encrypted connection. Setup is documented in HTTPS for WordPress.

Turn on a certificate in the hosting panel, then set WordPress Address (URL) and Site Address (URL) under Settings → General so both start with https://. Turn on the host's HTTP-to-HTTPS redirect if it has one. A mixed-content warning afterwards usually means an image or script is still loaded over http://. Fix that URL. Do not click through browser warnings on your own login.

Give each person the least access they need

Every account is a way in. WordPress documents roles on its roles and capabilities page. On a single site:

RoleEveryday use
AdministratorPlugins, themes, settings, and users
EditorPublish and manage all posts and pages
AuthorWrite and publish their own posts
ContributorWrite posts, but not publish them
SubscriberManage their own profile

A writer does not need to be an administrator. Keep administrators few. Open Users, delete accounts for people who have left, and delete any user you do not recognise. Do not share one administrator login. You cannot see who changed what, and you cannot remove one person without locking out the others.

Make the login harder to guess

WordPress does not stop a script from trying passwords all day. A security plugin or the host can block an address after repeated failures. Turn that on if your tool offers it, and keep backup codes or host support as a way back in.

Do not use an administrator name such as admin or webmaster. The hardening guide says those names are tried first. On an existing site, create a new administrator, log in as that person, and only then delete or demote admin.

The guide also shows a database rename. Use it only if you back up the database and know your table prefix. The default is wp_, and many sites change it:

UPDATE wp_users SET user_login = 'newuser' WHERE user_login = 'admin';

If that is unclear, stay in the dashboard. A wrong query can lock you out.

An optional extra is a second password, at the web server, in front of wp-admin. The hardening guide warns that this can break wp-admin/admin-ajax.php, which some public features use. Follow the guide's notes if you add it. It is not the first step.

Choose hosting that handles the basics

The hardening guide says to run current server software, or to use a host that does, and it warns that on a shared server another customer's compromised site can affect yours. Ask what the host isolates.

WordPress's requirements recommend PHP 8.3 or greater, a current MariaDB or MySQL, and HTTPS. The same page says WordPress also runs on PHP 7.4 and newer, but those older versions are past end of life and can leave the site open to security problems. Switch PHP in the hosting panel, then click through the site. Back up first, because an old theme sometimes needs a fix on a newer PHP.

Ask the host four things: who applies PHP security updates, whether accounts are isolated, whether they scan for malware and tell you, and whether backups are automatic, stored off the server, and restorable by you. Use SFTP rather than plain FTP. The hardening guide says SFTP encrypts the password in transit.

Harden a few settings

Back up first. The dashboard file editor runs PHP, and the hardening guide says attackers use it after a successful login. Disable it by adding this line to wp-config.php, above the "stop editing" line:

define( 'DISALLOW_FILE_EDIT', true );

That removes the theme and plugin editors. It does not stop plugin updates, and it does not stop every way of uploading a file.

The guide's permission rule is directories at 755 and files at 644. WordPress needs to write in wp-content for uploads. It does not need every file writable by everyone. With your own path, the guide's commands are:

find /path/to/your/wordpress/install/ -type d -exec chmod 755 {} \;
find /path/to/your/wordpress/install/ -type f -exec chmod 644 {} \;

Run them only on the WordPress directory. Keep wp-config.php readable only by you and the web server, often 400 or 440. It holds the database password.

XML-RPC is an older remote interface used by the mobile app, Jetpack, and some remote publishing. If you need none of those, you can disable the methods that require a password. The xmlrpc_enabled reference says this filter does not turn off all of XML-RPC. Pingbacks and other endpoints that do not ask for a login can remain. The reference shows:

add_filter( 'xmlrpc_enabled', '__return_false' );

Put that in a small custom plugin, not in a theme you might switch off. If the mobile app or Jetpack stops connecting, remove the line.

What to do if the site is hacked

If Google warns visitors, the site redirects, or you find users or files you did not create, treat it as compromised. Start with Help, I think I've been hacked. Search Central's Search Console guide describes the Security Issues report as the place those warnings appear.

  1. Take the site offline. Google's quarantine guide says to stop serving the compromised pages, for example with HTTP 503 from a static page that is not the infected site. A host can often do this from outside those files.
  2. Change every password. WordPress, the host, the database, SFTP, and the email account that can reset them. Use new unique passwords, and turn two-factor login back on.
  3. Restore a clean backup from before the compromise. Check that the backup does not already contain the bad files or the extra admin. Without a clean backup, cleanup is slower and easier to get wrong.
  4. Update WordPress, plugins, and themes, and delete what you do not use. Move off end-of-life PHP. The opening is often an old plugin.
  5. Check users in WordPress and in Search Console → Users and permissions. Remove accounts and verification files you did not add.
  6. Scan with the host or your security plugin. Look for PHP files in the uploads folder, then click through the public pages while logged out.
  7. Request a review in the Security Issues report only after the clean site is online and Googlebot can fetch it. Google's review article says a review of a site that is still hacked prolongs the warning. Say what you removed and what you updated. Do not leave the pages on noindex.

Security checklist

  1. Install waiting updates, and enable auto-updates for what you keep.
  2. Delete unused plugins and themes. Keep one default theme.
  3. Keep a scheduled backup off the server, and restore one as a test.
  4. Give every administrator a long unique password.
  5. Turn on two-factor authentication, and store backup codes off the server.
  6. Install one security plugin or firewall you understand.
  7. Serve the site over HTTPS, including both address settings.
  8. Give each person only the role they need. Delete old accounts.
  9. Limit repeated login attempts if your plugin or host can.
  10. Replace an administrator named admin.
  11. Set DISALLOW_FILE_EDIT in wp-config.php.
  12. Use 755 for directories and 644 for files. Keep wp-config.php tighter.
  13. Run a PHP version WordPress currently recommends.
  14. Disable authenticated XML-RPC only if nothing you use depends on it.
  15. After a hack: take the site offline, change passwords, restore a clean backup, update, check users, scan, then request a Search Console review.

Frequently asked questions

What should I do first to secure a WordPress site?

Update WordPress, plugins, and themes, delete what you do not use, and confirm a backup lives off the server. Then change administrator passwords and turn on two-factor authentication. Configuration changes help. They do not replace updates and backups.

Is a security plugin enough on its own?

No. A plugin or firewall is one layer. It does not update abandoned software and it does not replace a backup you have tested. Use it in addition to updates, passwords, and backups.

Should I turn off XML-RPC?

Turn off authenticated XML-RPC if you do not use the WordPress mobile app, Jetpack, or remote publishing. The xmlrpc_enabled filter does that, and the developer reference says it does not disable every XML-RPC endpoint. Remove the filter if a tool you need stops connecting.

How do I ask Google to review the site after a hack?

Clean the site first. In Search Console, open the Security Issues report and choose Request a review. The pages must be online for Googlebot, and the request should say what you removed and what you updated.

Can I do this without a developer?

Updates, users, passwords, HTTPS, and backups are dashboard and hosting-panel work. Editing wp-config.php, permissions, and XML-RPC is ordinary maintenance. Ask your host if you have not edited server files before, and back up first.

Sources

Aukark offers WordPress development and maintenance in Gurugram. See WordPress website development in Gurgaon and website maintenance services in Gurgaon.

By Lokendra Singh, Founder of Aukark.

Lokendra Singh founded Aukark on 14 November 2020 in Gurugram and leads the studio. Read the editorial policy.

Follow Aukark: LinkedIn · Facebook · Instagram · Google · Clutch · GoodFirms

Share this page: Share on LinkedIn · Share on Facebook · Share on X

Ready to accelerate your growth?