WordPress is the world's most commonly used Opensource Web Application. What makes it so preferred amongst website creators is the ease of use, the vast expandability, and the knowledgeable community that supports it. WordPress ships by default with quite a lot of useful features that will allow you to build your website easily and promptly. One of those is its ability to execute certain web tasks automatically without the interaction of the website administrator.
The automated execution of web scripts is called a cron task and typically it is supported by the Control Panel of your Web Hosting account. In this case, however, this functionality is been included as part of WordPress.
Here is how it works - whenever a page on your website is loaded, the "wp-cron" functionality is initiated with the execution of a php script part of WordPress - "wp-cron.php". This script checks for scheduled tasks, and if there are such, they will be executed immediately or when scheduled.
By default, WordPress has that functionality enabled and often the same is used as a target of malicious attacks aimed at compromising your entire website. Another negative aspect of this functionality is that sometimes it can trigger the execution of scheduled tasks by plugins and themes that are not tested well enough resulting in the consumption of all the hardware resources for your Web Hosting Account. To prevent these and many other negative scenarios you are given the option to completely disable the "wp-cron" functionality and in the next lines of this article, we will explain how that can be achieved.
How to Disable the built-in WordPress cron functionality
Disabling the "wp-cron" functionality is a straightforward procedure. It revolves around adding or modifying an existing line of code in WordPress's configuration file - wp-config.php. If you are not sure where this file is located, please check our tutorial on the matter. Here are the steps you need to follow:
- You may use a few methods to change it - SSH, FTP, or the cPanel's FileManager.
- When you choose an editing method, please open the file and add the following line:
define('DISABLE_WP_CRON', true);
inside it. Make sure to add it AFTER the<?php
tag, otherwise, WordPress will not be able to interpret your code and will result in an error. To ensure that you do it correctly, add it to the very bottom of the page. - If the line already exists, please make sure that the string after "DISABLE_WP_CRON" is set to "true". If not, then modify just this part of the code and save the file.
Another useful trick you can apply to disable the internal WordPress cron is changing the permissions of the wp-cron.php file to 000. These specific permissions will prevent the user (in this case, yourself), the user group, and everyone else from being able to execute this file, thus disabling its functionality.
How to enable the built-in WordPress cron functionality
- It is utterly analogical to the above. When you chose a method to edit the wp-config.php file add the <pre>
define('DISABLE_WP_CRON', false);
line AFTER the<?php
tag. - If the snippet of code exists, make sure that the string after the "DISABLE_WP_CRON" is set to "false". If not, then modify just this part of the code and save the file.
How to disable the internal WordPress cron feature and implement it from the cPanel
This method revolves around setting your own cron job from the cPanel that will handle the built-in functionality WordPress has. If you are not sure how to set up a cron job in cPanel, please check out our tutorial. Please make sure that the snippet of code
define('DISABLE_WP_CRON', true);
exists in your wp-config.php file and the permissions of the "wp-cron.php" file are at least 644.
The cron job you need to configure inside cPanel is as follows
wget -q -O - http://yourwordpresswebsite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
The time frame in which it should be executed should be at least once everyone 30 minutes. Please replace “yourwordpresswebsite.com” with the actual domain name where your WordPress installation can be accessed.
If you are a client of HostArmada and you do not feel confident enough doing the above procedures yourself, please feel free to contact our technical support team. They are 24/7 available at your disposal, and they will be happy to assist you.