The cron command-line utility is a job scheduler which is installed by default on UNIX and linux systems. The Microsoft Windows equivalent is Windows Task Scheduler, or schtasks.
WordPress includes a built-in PHP function called wp-cron which acts as a cron service. This allows WordPress to check for plugin and theme updates, send emails and run any other maintenance-related tasks.
This wp-cron function is automatically executed whenever someone accesses the website. This is acceptable when only a small handful of people are accessing the website, but as user demand scales up to dozens of users, this create an exponential load on the server and eventually degrades performance.
It is therefore best-practice to disable wp-cron within WordPress (Step 1), and enable it on the server as a scheduled task (Step 2).
Step 1. Disable wp-cron in WordPress
Open wp-config.php in your WordPress installation from the terminal:
sudo nano wp-config.php
Add the following line to wp-config.php
define( 'DISABLE_WP_CRON', true);
Step 2. Enable cron on the server
Open the crontab scheduler (in edit mode) by running the following command in the terminal:
Insert the following line, making sure to use the correct domain. This will insert a cron job which runs every 5 minutes:
5 * * * * wget -q -O - https://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
Notation for a subdomain:
5 * * * * wget -q -O - https://subdomain.yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
Notation for a subsite:
5 * * * * wget -q -O - https://yourdomain.com/subsite/wp-cron.php?doing_wp_cron >/dev/null 2>&1
Error in Site Health
Once you’ve switched from WordPress cron to server cron, you will find the following ‘error’ in Site Health. This is a known issue and will hopefully be addressed in a future version of WordPress.
That’s it! You’re done.