The virtual WordPress “cron job”

A cron job is a task scheduled to run automatically at specific intervals. For example, a cron job could automatically back up a file every six hours.

In its default configuration, WordPress does not use a real cron job for scheduling and other related tasks. Instead, whenever a page is loaded on a WordPress site, WordPress runs the wp-cron.php file. Although this “virtual” cron job is convenient, it has a few disadvantages:

Running the wp-cron.php file every time WordPress loads a page is unnecessary, and can negatively affect server performance, particularly on sites that receive a lot of traffic.
For a site that does not receive a lot of traffic on the other hand, it can be a significant amount of time before a visitor loads a page (and triggers the cron task). This can cause missed schedules for publishing posts and other unintended effects.

Disabling the virtual WordPress cron job

To disable the default virtual WordPress cron job, follow these steps:

  1. Use Filezilla to FTP in to the website that would like to disable the virtual cron job on
  2. Navigate to public_html  and open the wp-config.php file in a text editor. If you FTP directly into the website as oppose to the server, you will probably start off in the public_html folder
  3. Add the following line to the wp-config.php file: define(‘DISABLE_WP_CRON’, true);
    Note – it might be wise to check to make sure that there is not already a bit of code in the file that disables WP Cron, to avoild duplication
  4. Save the changes to the wp-config.php file and then exit the text editor. The virtual WordPress cron job is now disabled.

Configuring a real cron job for WordPress

After you have disabled the default WordPress cron configuration in the wp-config.php file, you are ready to set up a real cron job that runs at fixed intervals regardless of site traffic.

If your account includes cPanel access, you can use it to configure the cron job. Otherwise, you can configure the cron job from the command line.

Method #1: Use cPanel

To set up a WordPress cron job using cPanel, follow these steps:

  1. Log in to cPanel.
  2. In the Advanced section of the cPanel home screen, click Cron jobs.
  3. Under Cron Email, type the e-mail address that you want to receive notifications, and then click Update Email. Every time the cron job runs, the e-mail account will receive a message.
    If you do not want to receive e-mail notifications for the cron job, you can append >/dev/null 2>&1 to the command, which redirects all output to /dev/null.
  4. Under Add New Cron Job, in the Common Settings list box, select Twice an hour.
    You can run cron jobs a maximum of every 15 minutes on shared and reseller accounts. A 30-minute interval for the WordPress cron job should be more than sufficient.
  5. In the Command text box, type the following line:
    cd ${HOME}/public_html; /usr/local/bin/php -q wp-cron.php
    This line assumes that you installed WordPress in the document root (public_html) directory. If you installed WordPress in another directory, modify the cd command to change to that directory instead.
  6. Click Add New Cron Job. The new cron job settings take effect immediately.