General info sources
- https://www.antagonist.nl/help/nl/webhosting/advanced/cronjob
- https://kinsta.com/nl/kennisbank/uitschakelen-wp-cron/
- https://chemicloud.com/kb/article/disable-wp-cron-wordpress/
- https://www.xxlhosting.nl/handleidingen/472-site-versnellen-door-wpcron-automatisch-uit-te-voeren/
WP Cron Jobs
With every page load WordPress checks if there are scheduled tasks, but
- A task is delayed when a site doesn’t get much traffic.
- It can slowdown sites with many visitors, because it runs with every visit.
- It isn’t reliable if you use a caching plugin, which loads pages from cache instead of from the database.
You can disable WP Cron jobs and schedule them yourself on the webserver, or use an alternate method.
Disable standard WP Cron Jobs
Disable cron jobs that are triggered by page visit in the WP Config file. Then schedule your own cronjob on the webserver as mentioned before.
The following code must be added before the wp-settings.php include.
define('DISABLE_WP_CRON', true);
Code language: JavaScript (javascript)
Schedule WP Cron (standard)
Create a WP cron job to execute the wp-cron.php file with php.
(Change the domain name as needed)
*/5 * * * * wget -q -O - 'https://www.domain.nl/wp-cron.php?doing_wp_cron' >/dev/null 2>&1
Code language: JavaScript (javascript)
- */5: run every 5 minutes
- url: address to the cron job
- >/dev/null 2>&1: disables email messages
Schedule WP Cron (CLI alternative)
An alternative is to use WP CLI to schedule a cron
/usr/local/bin/php /usr/local/bin/wp cron event run --due-now --path=/home/USER/public_html
Code language: JavaScript (javascript)
- /usr/local/bin/php: tells the script to use the PHP binary to execute the command. You can confirm this is correct for you with the command “whereis php” from your Terminal in cPanel.
- /usr/local/bin/wp: tells PHP to use the WP-CLI binary program.
- cron event run –due-now: asks WP-CLI to execute any tasks that are currently due.
- –path=/home/USER/public_html: USER = the cPanel user. Since WP-CLI executes in the directory that it is run from, we need to specify exactly where WordPress is installed. You will need to modify this line to match your installation.
HWS cron @ Hoasted
The cron jobs from above didn’t work as expected. Hoasted helped and changed to the below. On another site with Hoasted, this one didn’t work while the wget version did.
/usr/local/bin/wp cron event run --due-now --path=/home/hwsjp/public_html > /dev/null 2>&1
Code language: JavaScript (javascript)
Alternate WP Cron Job
Can be used if hosts block access to the wp-cron.php file, or as an alternative to the default method.
It adds “/?doing_wp_cron” to the end of url’s to execute the WP Tasks.
https://arnesonium.com/2016/03/alternate-ways-to-call-wp-cron/
define('ALTERNATE_WP_CRON', true);
Code language: JavaScript (javascript)
Like so
wget -q -O - https://www.domain.nl/wp-cron.php?doing_wp_cron >/dev/null 2>&1
Code language: JavaScript (javascript)
Test Cron jobs
Execute 1 to 3 to retrieve the current WP Cron list. Repeat the third one to refresh.
The order of the list should change after cron’s have been executed.
The configures cron doesn’t work if the records on the top are past the next_run_gmt time with keep next_run_relative = now.
- Start terminal from hosting panel
- cd public_html (specify location of the website)
- wp cron event list (shows current WP Cron list, enter command 2x if it doesn’t work)
To execute the cron tasks:
- wp cron event run –due-now