10 Ways to Keep Your WordPress Site from Getting Hacked

Keep Your WordPress Site From Getting Hacked, FixMyWP guide header image

Keep your WordPress site from getting hacked with the following tips and instructions. With thousands of websites getting hacked every day, your WordPress website could easily be the next victim.

If your website gets hacked, you will lose all the time and money you have spent building your website. Not only that, if your site gets hacked, Google may warn visitors away from it or drop it from search results. Google flags hacked websites with warnings in its search results and in Chrome.

While WordPress itself is very secure, there are a few ways you can improve the security of your website. In this article, we will share a few easy ways to prevent WordPress hacking and protect your website from hackers.

Let Us Handle Fixing Your Hacked WordPress Site

Why Do WordPress Sites Get Hacked?

WordPress itself is a very secure platform and receives regular security updates from its developers. When a WordPress site gets hacked, most of the time, it is the fault of the user running the site. The Security team behind WordPress fixes security issues as soon as they find them. Many times they fix these issues in less than 24 hours.

One of the most common reasons WordPress sites get hacked, and the first thing to check if your WordPress site keeps getting hacked, is an out-of-date version of WordPress. When your site is running an out-of-date version of WordPress, it becomes vulnerable to hackers.

WordPress Security team releases new security updates for the software as soon as they find new bugs. And all the WordPress sites running a version of the software below the latest become vulnerable to hackers.

The hackers can easily find sites that are vulnerable. They only have to look for websites that are running WordPress version that is out-of-date and vulnerable. Once they find a site that is vulnerable, they will go through all the documented vulnerabilities of the out-of-date version of WordPress and use those vulnerabilities to hack the website.

If you don’t keep your WordPress core up-to-date, your site will become vulnerable to hackers sooner or later.

Running an outdated version of WordPress on your site is not the only reason why your site can get hacked. There are a lot of other reasons as well.

The themes and plugins you use can also make your website vulnerable to hackers. Running an out-of-date version of a theme or plugin can also make your WordPress site vulnerable.

It is really important that you choose your theme and plugin providers carefully. Keep your WordPress site from getting hacked by purchasing themes and plugins from trusted developers who release new updates for their themes and plugins on a regular basis.

Let Us Handle Fixing Your Hacked WordPress Site

10 Ways to Keep Your WordPress Site from Getting Hacked

Now that you know why WordPress sites get hacked, let’s get started:

Keep The WordPress Core Up-to-date

This is one of the most basic and the most important tips you will read in this guide.

If you don’t keep WordPress up-to-date, none of the other tips in this guide will matter. You need to update WordPress as soon as a new update is released by the WordPress team. Not doing so will sooner or later make your site vulnerable to hackers.

WordPress installs minor and security releases automatically by default, and you should leave that on. You can turn on automatic updates for major releases too, but if a plugin or theme doesn’t support the latest version of WordPress, a major update can break your site. Test major updates on a staging site first.

Updating WordPress regularly can be a hassle. You can instead use a WordPress management service like ours and leave it to the service to update and maintain your site.

Regularly Backup Your WordPress Site

If your site gets hacked, you will lose the countless hours of work you have put into building your website. Regular backups will give you the ability to restore your site as soon as it gets hacked.

If you are running your site on a managed WordPress hosting service, your hosting company will take care of backing up your site. But if you are not on a managed WordPress hosting service, do not rely only on the regular backups offered by most web hosts. These backups are often kept for a short time and may not be easy to restore on your own.

The best way to backup your WordPress site is by either doing it manually or using a plugin. You can use a plugin such as UpdraftPlus or Solid Backups (formerly BackupBuddy) to automate the task of creating regular backups of your WordPress site. These backups will be available to restore with just one click.

Don’t Use admin Username

This is a mistake I see almost all beginners make. They use the admin username. You are not the only person who knows the default WordPress username. Hackers know it too. And when you use the default username, admin, hackers only have to guess your password which makes the task of hacking into your website easier.

Instead of using the default username that comes with WordPress, use a username that is relatively difficult to guess. Try including numbers in your username. The more difficult you make your username to guess, the better.

Rename The wp-admin Directory

The wp-admin directory is where your WordPress site’s dashboard exists. The default URL looks something like this:

http://your-site.com/wp-admin

This URL is the default and hackers know that too. You need to make your login URL difficult to guess for hackers. Once a hacker gains access to your WordPress dashboard, she can delete all your data or change the look of your website or even inject invisible malicious code into your themes and plugins.

Renaming your WordPress site’s admin directory will make it much harder for hackers to guess where they can log in or locate the admin dashboard. The wp-admin directory is not the only URL that you should change. The wp-login.php file is another file that you will have to rename.

To rename the URL, use the free Protect Your Admin plugin. Once you install it, you will be able to customize the URL and change wp-admin with your own custom string. It will also allow you to rename the wp-login.php file. Try using a combination of random words to make it difficult to guess for hackers.

Password Protect The wp-admin Directory

The wp-admin directory contains some of the most important files of your WordPress website. This directory is where your admin dashboard is located. If a hacker gains access to your dashboard, she can do anything she wants to your website.

Using Apache’s (your server) built-in directory password protection, you can easily add an additional layer of security to this directory.

To do this, use your host’s control panel (Directory Privacy in cPanel, or Protected URLs in SiteGround Site Tools). The free AskApache Password Protect plugin used to do this from the dashboard, but it was closed on WordPress.org in 2020 because of a security issue, so do not install it. Either way, a .htpasswd file will password protect your admin directory, and to log in after that, you will have to enter an additional username and password:

Leave /wp-admin/admin-ajax.php unprotected, because many themes and plugins use it on the front end of your site.

Use a Unique Name For The Table Prefix

Every table in WordPress database follows a prefix you set when installing WordPress.

To manipulate the data in your database, a hacker needs to know the exact names of the tables. And if you are using the default prefix, it will be really easy for them to guess the names of your database tables.

Keep your WordPress site from Getting hacked by using a unique default table prefix, one that isn’t an acronym for your blog, and contains both letters and numbers.

The next time you install WordPress, remember to change the default table prefix. If you have already installed WordPress, changing the prefix means renaming every table and updating the option and user meta keys that contain the old prefix, so take a full backup first. The free WP DB Manager plugin is an easy way to back up your database before you make the change (it does not rename the prefix itself).

Think your site has been hacked? We remove the malware, close the hole it came through and lock the site down for a flat $249. See malware removal →

Disable File Editing In WordPress Dashboard

The file editing feature offered by WordPress allows you to edit your theme and plugin files directly from the dashboard. While this functionality can be helpful at times, it can be really dangerous if a hacker gets access to your WordPress dashboard.

A hacker can use this helpful feature to inject malicious code into your themes and plugins. Disabling File Editing in WordPress is a preventive measure that will only allow you to edit your WordPress files via FTP. This will add an additional layer of security to your site.

To disable file editing, place the following code in your wp-config.php file, above the line that says “That’s all, stop editing!”:

				
					define( 'DISALLOW_FILE_EDIT', true );
				
			

Prevent Brute Force Login Attempts

If the hacker doesn’t know your username and password, they will try to guess both of these to log into your WordPress dashboard. While guessing these manually is impossible, it is really easy when using a password guessing (brute force) tool. These tools try hundreds of random username and password combinations every second until they find the one that actually works.

By default, WordPress allows unlimited login attempts. This makes it vulnerable to brute force attacks. Keep your WordPress site from getting hacked by preventing these brute force login attempts.

To prevent this, you can use the free Login Lockdown plugin (now called Login Lockdown & Protection). It blocks a visitor once they have made a specific number of failed login attempts. This will at the very least slow down brute force attacks, and in most cases make them fruitless.

Use a Complex, Long Password to Keep Your WordPress Site from Getting Hacked

This is one of the most basic and the most important tips in this article. It’s common sense to use a complex password. But not many of us do it.

Weak passwords are one of the top reasons why accounts (WordPress, Facebook or Twitter) get hacked. Weak passwords are easy to guess. Even if you think your password is impossible to guess for a human being, it’s probably not so much for a computer. Hackers can use brute force tools to try hundreds of random username and password combinations per second to find the one that works.

Use a password that is long and contains special characters. If you can’t come up with a good password yourself, use the Generate Password button on your WordPress profile page or the generator in your password manager.

The best way to do this is to use a password generator tool to generate a complex, long password that is nearly impossible to guess. These random passwords will almost always be really difficult to remember and guess as they will contain multiple special characters. You can use a password manager such as Bitwarden or 1Password to save the password in your account and be able to use it across devices without even knowing it.

Related Post: WebShell Backdoor Attacks

Hide Your wp-config.php File

Wp-config is one of the most important files of your WordPress site. It contains important information such as database name, database username and password. Hackers can use this file to do anything they want to your website. They can change the contents or delete everything on your website.

While wp-config.php file is very secure, it is always better to have some preventive measures in place. To keep your WordPress site from getting hacked, the best and the easiest way to secure your wp-config file is to move it out of the public directory.

The public directory of your website contains all the files that are accessible by users. These files include but are not limited to your login page, your posts and pages, and your images.

In most cases, the public directory that contains your website will be named “public_html.” This folder contains all the files and folders that are supposed to be accessible by the general public.

When you move the wp-config file one folder above the public directory, it becomes virtually impossible for a hacker to get access to the file.

The process is really simple. Here’s a simple, detailed tutorial on how to do it.

Use Two-Factor Authentication

You have probably seen and are using two-factor authentication every day. It’s basically a way to add an additional security layer

Here’s how two-factor authentication works: You enter your username and password, and then get a randomly generated code sent to your phone. You will only be able to login once you enter this code.

Instead of just entering a username and password, you have to enter a dynamically generated code or scan a randomly generated barcode (depending on which app you use.)

Two-Factor Authentication acts as an additional layer of security. It is possible for a hacker to guess a username and password with brute force. But it is virtually impossible for her to guess a randomly generated dynamic code.

You can use the free (unofficial) Google Authenticator plugin for WordPress, or the free Two Factor plugin maintained by WordPress contributors, to enable two-factor authentication.

Invest In a Trusted Web Hosting Service to Keep Your WordPress Site from Getting Hacked

Most cheap website hosting services aren’t as secure as they might appear from the outside. Most web hosting services like to boast they are the best when it comes to security. But the truth is that most of these web hosting services aren’t as secure as they would like to say. Numerous web hosting companies get hacked every week. When this happens, all the sites on the hacked web hosting services are accessible by the hackers.

If a hacker hijacks your web hosting service’s server, they can access data for all the websites on the server and manipulate it as they please. They can also delete all the files and data from the server.

So, it is really important that you invest in a trusted web hosting service.

Related: Our sister company LeDetailWP offers managed WordPress hosting plans with free migration.

Disable PHP Error Reporting

PHP Error Reporting functionality is a godsend for developers. It allows them to easily detect bugs in their applications. But the problem with PHP Error Reporting is that it reveals too much information about how an error happened. This information can be very useful to a hacker. The hacker can use this information to devise the best ways to gain access to your servers. Keep your WordPress site from getting hacked by making these changes:

A production server environment should not have PHP Error Reporting enabled.

Many web hosts turn off error display by default, but check yours. If it is on, you will have to turn it off manually.

The easiest and fastest way is to create a php.ini file (or edit one if it already exists) in the root public directory of your website.

Place the following lines into the file:

				
					display_errors = Off
log_errors = On
				
			

These lines hide PHP errors from visitors while still writing them to the server’s error log, so you can still find problems. Many hosts also let you change these PHP settings in their control panel. In WordPress, you can add define( 'WP_DEBUG_DISPLAY', false ); to wp-config.php as well.

Don’t use email as login to keep your WordPress site from getting hacked

By default, WordPress allows you to log in with both your email and your username. Your email address is often public, on your contact page or in your posts, so it gives attackers one more login name to try.

Keep your WordPress site from getting hacked by using a login email address that is not published anywhere on your site. Also set “Display name publicly as” in your profile to something other than your username. (The WP Email Login plugin we used to suggest is no longer needed, because WordPress has supported email logins on its own since version 4.5.)

Hide Your WordPress Version

If your website is running an older version of WordPress and a hacker figures out the version, it will become much easier for them to hack your website. All they will have to do is find all the documented vulnerabilities there were in the old version your site is using.

Even if you keep your WordPress site up-to-date, it is recommended that you hide your WordPress version to keep your WordPress site from getting hacked.

Related Posts: WordPress Hacked Redirect, How to Detect and Clean it

To hide your website’s WordPress version, you can use the following code from WPMU DEV:

				
					/* Hide WP version strings from scripts and styles
 * @return {string} $src
 * @filter script_loader_src
 * @filter style_loader_src
 */
function fjarrett_remove_wp_version_strings( $src ) {
    global $wp_version;
    parse_str( (string) parse_url( $src, PHP_URL_QUERY ), $query );
    if ( ! empty( $query['ver'] ) && $query['ver'] === $wp_version ) {
        $src = remove_query_arg( 'ver', $src );
    }
    return $src;
}
add_filter( 'script_loader_src', 'fjarrett_remove_wp_version_strings' );
add_filter( 'style_loader_src', 'fjarrett_remove_wp_version_strings' );
/* Hide WP version strings from generator meta tag */
function wpmudev_remove_version() {
    return '';
}
add_filter( 'the_generator', 'wpmudev_remove_version' );
				
			

Place the above code at the end of your child theme’s functions.php file, or add it with a code snippets plugin.

★★★★★
When my sites got hacked and my webhost said, “Sorry, can’t help you!” FixMyWP stepped in to clean out the sites in their trademark meticulous manner–all while keeping the pricing honest and reasonable.
Lee Wallender
thedatinggurus.com

Conclusion

All the tips we shared in this article are fairly easy to implement and most of them will not take more than a few minutes to implement. To keep your WordPress site from getting hacked and prevent WordPress hacks and downtime, don’t wait: implement these tips today to make your website secure from hackers.

Has your website ever been hacked before?

Do you have any of your own tips and tricks to share?

Let us know in the comments below.

Think your site has been hacked?

We remove the malware, close the hole it came through and lock the site down. Flat rate of $249, usually done the same day or within 24 business hours.

See malware removalNot sure? Answer 4 quick questions

In this article

Need a hand with your site?

Answer four quick questions and see your flat price before you pay. Most fixes are done the same day or within 24 business hours.

Related articles