About WP Cron
WordPress Cron (WP Cron, wp-cron.php) is the internal task scheduler in WordPress website. It is used to run WordPress scheduled tasks. Many WP plugin are relying on WP Cron to run their backend functions.
By default WP Cron is triggered by website visits: every time a visitor load your website, there is a small chance that your WP Cron is triggered, and it'll execute on scheduled. This may not be good for you:
- The website load speed will be decreased, as it must execute backend functions.
- It eats up your server resources e.g. CPU cycles, memory, etc, as it needs to check the scheduled task list every time it's triggered.
- It's not stable, as it depends on website visits. If there is no visits for some time, the backend tasks will not be executed.
- It's not on time. If you want some functions to execute at an exact time, you'd better use a decent cronjob service like SetCronJob.
To set up cronjobs for WP Cron, follow these step by step:
Disabling WP Cron
- Open your wp-config.php file with a file manager (e.g. cPanel file manager)
Go to the bottom of the database settings in wp-config.php typically around line 37.
Add the code below highlighted in red:
/** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', ''); define('DISABLE_WP_CRON', 'true');
- Click Save
Set up cronjob at SetCronJob
- Log in to your SetCronJob account
- Click Add a cronjob
- Enter the URL to call:
http://yoursite.com/wp-cron.php?__random__(replace http://yoursite.com/ with your actual WordPress homepage URL)
- Select When to call: Every hour
- Click Save changes
and you're done!
You may notice that I added
?__random__ into the cronjob URL. It'll add a random number every time your cronjob is executed, so it'll prevent your web server from caching the HTTP request.