Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Create and Change a WordPress Cron Job

Schedule tasks in WordPress with the WP Crontrol plugin, or run them from a real cron job in cPanel.

WordPress2 min read10 steps11 screenshots

What WordPress cron does

Cron schedules tasks that run on their own. WordPress has its own system, WP-Cron, in the file wp-cron.php. It publishes scheduled posts, checks for updates, sends newsletters and runs tasks for plugins.

WordPress cron jobs

WP-Cron has one weakness: it only runs when someone visits the site. On a site with little traffic, tasks can run late. A very busy site can run it too often. The more reliable way is to call wp-cron.php from a real server cron job (see the last part of this guide).

Good

  • Automates repeated jobs such as newsletters and spam cleaning.
  • Many plugins need it to work.
  • Saves you time.

Not so good

  • Badly made plugin jobs can slow the server.
  • Jobs can fail or run late.
  • On low-traffic sites, jobs depend on visits.

Install WP Crontrol

WP Crontrol lets you view, add, edit and delete cron events in the dashboard.

  1. Go to Plugins, then Add New. Search for WP Crontrol, then install and activate it.
    Installing WP Crontrol
    Activating WP Crontrol
  2. You can now see all events under Tools, then Cron Events.

Add a schedule

Under Settings, then Cron Schedules, add a new interval, such as every five minutes.

Adding a cron schedule

You can also add a schedule in code. Put this in your functions.php (preferably in a child theme or a small plugin):

add_filter('cron_schedules', 'my_cron_schedule');
function my_cron_schedule($schedules) {
    $schedules['every_five_minutes'] = array(
        'interval' => 300, // 300 seconds = 5 minutes
        'display'  => __('Every 5 Minutes')
    );
    return $schedules;
}

Change an event

  1. Go to Tools, then Cron Events.
  2. Find the event and click Edit.
    The list of cron events
  3. Change the next run time or the schedule. Click Update Event.
    Editing a cron event

Run WP-Cron from a real cron job in cPanel

  1. First turn off the built-in trigger. Add this line to wp-config.php:
define('DISABLE_WP_CRON', true);
  1. Log in to cPanel. In the Advanced section, click Cron Jobs.
    Cron Jobs in cPanel
  2. Choose how often it should run. The Common Settings list has ready choices, or you can fill in the fields.
    The time fields
    Common Settings
  3. In Command, enter:
wget -q -O - https://example.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

Use your own domain. Click Add New Cron Job.

Entering the command
  1. The job appears under Current Cron Jobs. Use Edit or Delete to change it.
    The list of current cron jobs

Quick recap

  • WP-Cron runs when people visit. A real cron job is more reliable.
  • Use WP Crontrol to manage events.
  • Set DISABLE_WP_CRON and call wp-cron.php from cPanel cron.