How to Improve Your Wordpress' Website Security

Here are common WordPress security issues and how to improve your WordPress security including tips to avoid being hacked.

WordPress security has been an important topic ever since the content management system was released back in 2003. As with any highly popular piece of software with a long and rich history, the CMS can sometimes become the target of WordPress hackers. Hostile actions could include a cross-site scripting attack, sql injections, brute force attacks, and a number of other ways to gain unauthorized access. 

As hackers gain experience in finding new ways to exploit WordPress vulnerabilities, developers and security specialists get better at creating sites that are more difficult to breach. There are things developers and WordPress site owners can do if they don’t want hackers to gain access and bypass server security. In this article, we will discuss some actions a WordPress admin can perform to prevent a platform from becoming one of many hacked websites.

Enable Proper Permissions for wp-config.php and .htaccess on the Server


644 -rw-r–r– /home/user/wp-config.php

644 -rw-r–r– /home/user/cgi-bin/.htaccess

to secured permissions:

600 -rw——- /home/user/wp-config.php

600 -rw—— /home/user/cgi-bin/.htaccess

Use an Up-to-Date and Secure Version of PHP

As of October 6, 2021, the most recent and recommended version of WordPress is 7.4. One can always check for supported and secure PHP versions by following the link: . As with any piece of software, keeping everything up to date is an important factor for WP security.

Disable the Editing of Themes and Plugins From WordPress Admin Panel Level

If hackers gain access to an admin account, it will be very easy for them to input malicious code into themes and plugins. We are going to use DISALLOW_FILE_EDIT to disable file editing and improve website security. Here is how to do it:

<!--[if !supportLists]-->1.     <!--[endif]-->The first step is to open wp-config.php using a text editor.

<!--[if !supportLists]-->2.     <!--[endif]-->Within that file, find the line: /* That’s all, stop editing! Happy blogging. */ and place the following code above it: define( ‘DISALLOW_FILE_EDIT,' true );

<!--[if !supportLists]-->3.     <!--[endif]-->Save changes end exit the file.

<!--[if !supportLists]-->4.     <!--[endif]-->If you go to your WP dashboard and if you did everything correctly, the “Plugins > Editor” and “Appearance > Editor” links should no longer be visible

Keep Your WordPress Plugins Updated

It’s a good idea to follow technological blogs and WP fan groups on social media, such as Facebook. Many WordPress users share notifications about critical errors in specific WordPress plugins. If you see an error concerning one that you use on your WordPress website, perform an update immediately. Furthermore, make sure to delete unused plugins to avoid unnecessary security vulnerabilities.

Install WordPress Themes and Plugins Only From Trusted Sources

The safest way is to use the official database/repository. For WordPress themes this is

Trusted WordPress plugins can be found here:

The files in this repository have been verified, and likely subjected to malware scanning software before upload.

Change the wp_prefix in the Database During WordPress Installation

By default, WordPress installation proceeds with the wp_ prefix, but it is worth changing it to an original one during the process. By doing so, we will make it more difficult for malware to gain access to our database and extract data.

Do Not Use the Default 'Admin' Login, Use Strong Passwords

It is imperative to change the login to an original one. Strong passwords with multiple different symbols are also more difficult to crack.

Disable User Registration if You Do Not Need This Function

To do this:

1. Go to the Settings page, General section

2. Uncheck the “Anyone can register” field in the Membership section.

3. Save changes.

Disable Comments If They Are Unnecessary

There are several ways to do it, you can use code, the built-in options of WordPress, or a plugin.

To disable comments globally using WordPress itself, follow the steps below:

1. Go to Settings, the Discussion section

2. Uncheck the “Allow people to post comments on new articles” field

3. Save changes

You can also write your own code or use a plugin to achieve the same effect, but in this tutorial, we only present the fastest option.

Configure robots.txt to Block Unauthorized Access to WordPress Files

This file, which is placed in the main folder of the domain, acts as a signpost for Google crawlers showing the pages they should visit and index, and the ones they should not. You can use the example presented in the grey box here: (remembering to change to your own domain)

or have a look at the official Google guidelines for robots.txt:

Protect Yourself Against User Enumeration

User enumeration is a form of malicious activity that allows hackers to use brute force attacks in order to gain access to user accounts. Check out the discussion on StackExchange on how to reduce the risk:

Secure Access to wp-admin / wp-login.php, Two-Factor Authentication, Limited Login Attempts

This action can be performed in many ways. The most popular one is to limit access to specific IP addresses or to display an additional window with authentication information. We can also set up a limit for login attempts or use two-factor authentication.

Two-Factor Authentication

To set up this functionality, first, download the Google Authenticator plugin.

After installing, go to the Profile page and check the “Active” field in the Google Authenticator Settings:

Now it’s time to get the Google Authenticator app for Android or iOS.

After launching the authenticator, a request should appear to input a code or to scan a QR code. Go back to your plugin settings and either copy the code to your app or select “Show/Hide QR code” and scan it with your phone:

This will begin automatic configuration, you should accept all changes and then click “Update profile” on the “Your profile” subpage. From now on, each attempt at logging in will require two-factor authentication on the WordPress login page.

Login Attempt Limitation

As mentioned before, one other method of preventing brute force attacks is to limit the number of times a user can attempt to log in. How to do it?

Probably the simplest solution is to use one of the many WordPress security plugins, such as the WP Limit Login Attempts by Arshid. You can download the security plugin here:

Make Backup Copies Regularly

Even the best protection may not be enough to save your website from WordPress hackers. Therefore, make sure you always have a backup in case the worst happens. Check if your hosting provider makes regular backups every day. Alternatively, you can make use of the following security plugin:

Hide Information About the WordPress Versions You Use

The information about your version of WP can be of use to hackers, so there is really no need to share it freely. First, block access to your readme file by adding the following lines of code to your .htaccess file:

<files readme.html>    order allow,deny    deny from all    </files>

Second, use a security plugin to deactivate this information. One such plugin is Sucuri, which should automatically hide this information once it is activated, but verify this by visiting “Settings” > “Hardening” tab just to be sure.

You can also remove version information by adding the following lines of code either to a site-specific plugin or a code snippets plugin:

function wpbeginner_remove_version() { return ''; }

add_filter('the_generator', 'wpbeginner_remove_version');

Third, remove information on WP version in the CSS/JS files loaded on the website. Here is a link on how to do it, following the recommendations by user tjhole:

Block the Execution of PHP Scripts in Specific WP Catalogues

Disable PHP file execution in unnecessary directories to improve your security. Following the solutions at, open a text editor and type in the following code:

<Files *.php> deny from all </Files>

Save this file as .htaccess and upload it to /wp-content/uploads/ folders on your website.

Disable Access to the REST API of Your WordPress

If you aren't planning to use it, disable access by using the following plugin:

Limit or Disable Access to XML-RPC

If you are not using XML-RPC, disable it with:

function remove_xmlrpc_pingback_ping( $methods ) { unset($methods['']); unset($headers['X-Pingback']); return $methods; } add_filter('xmlrpc_enabled', '__return_false'); add_filter('xmlrpc_methods', 'remove_xmlrpc_pingback_ping' );

or with .htaccess:

<Files xmlrpc.php> Order deny,allow Deny from all </Files>

Check out this link if you need additional information:

Make Sure Your Website Has an SSL certificate

Theoretically, you could use a plugin to do it, but we recommend a more “manual” way suggested at Check out the “How to properly enable SSL in WordPress” section, and follow the guidelines.


Security should be a top priority of any enterprise, big or small. We hope you find these suggestions useful in the fight against hackers and malicious software. Make sure to follow us for other tips and guidelines.

Relevant Blogs:

Recent Comments

Lindsey John says:

Great article on improving WordPress website security! I found it really helpful. Thanks for sharing these valuable tips!

Leave a Comment