How do I set up WP Cron to make sure it runs on the specified intervals?
WP Cron is a task scheduler used by WordPress and our plugins extensively. WP Cron runs when someone visits your site. In other words, if no one visits your site, WP Cron does not run. In that case, the tasks scheduled by our plugins will not be executed or will be delayed until the next WP Cron run.
To make sure the scheduled tasks are executed in a reliable and predictable way, we have two options:
- Using operating system task scheduler
- Using an external webcron service
Before using any of the options above. You need to disable WP Cron from running by adding the following code to your wp-config.php file:
Using operating system task scheduler
You can use your operating system's task scheduler to trigger WP Cron at the specified intervals by following the steps below. Make sure to replace "Your_Site_URL" with your own domain URL.
There are multiple ways to schedule a task depending on your flavor of Windows. We've found that the easiest way to do it is the command line by using the schtasks command.
- Open a command prompt (Start > Programs > Accessories > Command Prompt)
- Enter the following code:
schtasks /create /tn "WordPress Cron Job" /tr "BROWSER_PATH http://Your_Site_URL/wp-cron.php" /sc TIME
Mac OS X/Linux
- Mac OS X and Linux have a time based task scheduler called cron. You can also use launchd service in Mac OSX. To start cron, go to command line and type in the following command:
- Use the image below to create your cron task:
Each cron task must be created in a separate line per site. A cron task consists of five parts:
- day of month
- day of week
For example, to run WP Cron at minute 5 every hour:
5 * * * * /usr/bin/wget -q -O - http://example.com/wp-cron.php?doing_wp_cron
If wget is not installed, you can use curl. The following command runs every 5 minutes.
*/5 * * * /usr/bin/curl --silent "https://example.com/wp-cron.php?" > /dev/null 2>&1
Alternatively, you can use special strings to define the time part of your task:
Run once, at startup.
Run once a year
0 0 1 1 *
Run once a month
0 0 1 * *
Run once a week
0 0 * * 0
Run once a day
0 0 * * *
Run once an hour
0 * * * *
For example, to run WP Cron daily at midnight:
@daily wget -q -O - http://Your_Site_URL/wp-cron.php?doing_wp_cron
Please note that if you're using our plugins in multiple sites, you should create a task to run WP Cron for every site.
Using an external webcron service
If using operating system level task scheduler is not an option for you. You can use one of the many webcron services to trigger your wp-cron.php at the specified intervals.