Alternate Ways to Call wp-cron

WordPress includes a job scheduling system called wp-cron. The default method for scheduled jobs is for wp-cron to be checked on each page load, which has the potential to slow down your website while background jobs are run. Check out these other options that help maintain the user experience on your WordPress site while still running important tasks in the background.

Using ALTERNATE_WP_CRON

The ALTERNATE_WP_CRON method uses a quick, nearly invisible redirect to direct an incoming user to a new request while the old one continues running, executing background jobs. This is an easy, effective method and it works really well if you don’t have access to crontab on your hosting site. Even though this method adds some elements to the page URL, it’s only triggered when background jobs need to be run. To enable it, follow these instructions:

  1. Open your site’s wp-config.php in your text editor.
  2. After the lines containing your database credentials, add the following lines:
1
2
/** Use alternate WP_CRON method with redirects. */
define('ALTERNATE_WP_CRON', true);

Read more about the ALTERNATE_WP_CRON method here.

Using Crontab

If you have access to a shell on your web host and can run cron jobs, this method might be the best. It ensures that background jobs will get run, even when your website isn’t getting any visitors. It also runs background jobs without requiring a redirect or any additional delays that will be noticed by users. Here’s how you do it.

Add a Crontab Entry

  1. Run crontab -e
  2. Add the following lines to the end of your crontab file:
1
2
# Call wp-cron regularly
*/15 * * * * curl http://www.example.com/wp-cron.php > /dev/null 2>&1

Make sure you replace “www.example.com” with your website’s hostname. The */15 specifies that wp-cron.php will be called every 15 minutes. If you would like to change this, replace the 15 with a different number.

Disable Built-in wp-cron

The next step is to disable the built-in call to wp-cron in WordPress.

  1. Open your site’s wp-config.php in your text editor.
  2. After the lines containing your database credentials, add the following lines:
1
2
/** Disable built-in cron in favor of system crontab */
define('DISABLE_WP_CRON', true);

For more details on this method, check out this page on EasyEngine.

2 thoughts on “Alternate Ways to Call wp-cron

Leave a Comment