Cron jobs are used to execute tasks on a regular basis – for example, every day, every month or at a specific day of the week. It is often used to perform automatic backups, updates, or when speaking of WordPress, to publish a post at a specific time.
In WordPress, there is a build-in system named WP-Cron that is fully independent of the operating system’s cron job functionalities, which makes it working without any configuration.
However, the downside is that the WordPress cron can put a strain on server resources, particularly if you have a large number of scheduled tasks, as it is triggered with each page load.
Disable the WordPress cron
Fortunately, you can disable the WordPress cron and replace it with a server cron job, which will allow you to schedule WordPress tasks more efficiently.
The first step is to locate the wp-config.php
file for your WordPress site. This file contains various configuration settings for your site, including the settings for the cron system. You can find the wp-config.php
file in the root directory of your WordPress installation.
Open it in a text editor and add the following line of code:
define('DISABLE_WP_CRON', true);
Should DISABLE_WP_CRON already exist, simply replace false with true (as displayed above).
This line of code will disable the built-in WordPress cron system. Save the file and exit the text editor.
Create a new cron job
Now that you have disabled the WordPress cron system, you need to create a new system cron job to replace it.
Using cPanel control panel
If you have a control panel such as cPanel, you can create a new cron job using the Cron Jobs feature. Here’s how:
- Log in to your cPanel account.
- Scroll down to the “Advanced” section and click on “Cron Jobs”.
- In the “Add New Cron Job” section, select the time interval at which you want the cron job to run (e.g., every 15 minutes).
- In the “Command” field, enter the following command (Replace “example.com” with your own domain name):
wget -q -O – http://example.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1 - Click on the “Add New Cron Job” button to save the cron job.
Using Cloud Panel
If you’re using our Cloud Panel, you can create a new cron job using the Cron Job feature. Here’s how:
- Log in to your Cloud Panel account.
- Click on the Application and “Cron Job” tab.
- Click on the “Create” button.
- Select the time interval at which you want the cron job to run (e.g., */5 for minutes followed by * for the other intervals).
- In the “Command” field, enter the following link replacing example.com it with your WordPress domain:
http://example.com/wp-cron.php?doing_wp_cron - Click on the “Create Task” button to save the cron job.
Test the cron job
To test the new system cron job, wait for 15 minutes and then check to see if any scheduled tasks have been executed. You can check this by going to the WordPress dashboard and looking at the task logs. If everything is working correctly, you should see that the tasks have been executed on schedule.
Conclusion
In conclusion, disabling the built-in WordPress cron system and replacing it with a system cron can help reduce server load and improve site performance. However, if you’re not comfortable making these changes yourself, don’t worry – every hosting package we offer includes fully managed support, and our team would be glad to apply these changes for you. Just reach out to us and we’ll take care of everything.