wp-cron is WordPress’ version of a cron job and a cron job is a task that is run on a schedule, whether just once at a particular date and time or on a recurring basis, like every day at 3pm, or every hour on the 15th minute.
Traditional Linux cron jobs run at precisely the time and date they are configured to run, much like the Task Scheduler function in Windows. However in most hosting environments WordPress doesn’t have full system access to be able to add itself to the operating system’s cron jobs, which is necessary for tasks to trigger at exactly their configured date and time.
To work around this, WordPress uses a best-effort (‘as close as we can get’) approach to scheduling tasks. Whenever a visitor views a non-server-cached page on the website (such as every admin page, or the WooCommerce cart), WordPress checks to see if it needs to run something in wp-cron and, if so, it proceeds to run through those scheduled tasks in the background and serves up the normal page that was requested as well.
The downside of this best-effort approach is that if most of your site’s traffic hits cached pages (which is optimal for performance), wp-cron will not have an opportunity to run because no dynamic processing is occurring to trigger it. To solve this, you’ll want to set up an actual system cron job in Plesk to trigger wp-cron. We’ll walk you through this process below.
WooCommerce Scheduled Events
If you are using WooCommerce, it also has its own scheduled events queue, but it does rely upon wp-cron to function.
WooCommerce has an excellent guide to troubleshooting wp-cron (whether you’re using WooCommerce or not) here. We strongly recommend checking it out if you think you’re having trouble with wp-cron.
Setting up wp-cron as a real cron job with Plesk
Time needed: 5 minutes.
If you suspect you’re having problems with a cron task, it can be very beneficial to decouple normal page views — like people adding things to their cart or checking out with WooCommerce, or any page view if you’re not using caching — from wp-cron, as you don’t want the scheduled tasks to interfere with important actions like a customer checking out.
Here’s how to do that on Plesk hosting:
- Disable auto-triggered wp-cron
To disable automatic triggering of the WordPress cron job, open the wp-config.php file in the root of your WordPress installation. You can modify the wp-config.php file via FTP, or Plesk File Manager. Look for either the line that says
define('DB_COLLATE', '');and right under it (or under the Other Customizations area), add the following on a line of its own:
- Set up a Scheduled Task in Plesk
Log in to Plesk and choose Websites & Domains > Scheduled Tasks > Add Task. Choose the option to Fetch a URL and enter the URL as: https://yourdomain.com/wp-cron.php
Set your schedule to run hourly (on a VPS you may enter a much more frequent schedule, however on shared hosting a very frequent scheduled task will likely be auto-terminated at some point in the near future).
Source: Plesk Customer Documentation