Performance PHP Beginner

Replace WP-Cron With a Real Cron Job

Stop WordPress running scheduled tasks during page loads, and run them on a schedule from your server instead.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
wp-config.php 7 lines
// In wp-config.php: stop WordPress triggering cron on page loads.
define( 'DISABLE_WP_CRON', true );

// Then add a server cron job that runs every 5 minutes, for example:
// */5 * * * * wget -q -O - "https://example.com/wp-cron.php?doing_wp_cron" >/dev/null 2>&1
// or, with WP-CLI:
// */5 * * * * cd /path/to/site && wp cron event run --due-now >/dev/null 2>&1

Where to add this

Recommended wp-config.php Above the line that says "That's all, stop editing!" in your wp-config.php file.

WordPress runs scheduled tasks such as publishing scheduled posts, sending emails and cleaning up by checking on page loads. On busy sites that adds work to visitors’ requests, and on quiet sites tasks run late because nobody visits. A real cron job fixes both.

How it works

DISABLE_WP_CRON stops WordPress spawning wp-cron.php during page loads. Scheduled events still exist; they just wait to be run.

A cron job on your server then calls wp-cron.php every few minutes, or runs wp cron event run --due-now with WP-CLI, so tasks run on time whether or not anyone visits. Most hosts have a “Cron jobs” or “Scheduled tasks” section in their control panel for this.

Things to watch

  • Only add the constant once the server cron job is set up. Without it, scheduled posts won’t publish and WooCommerce tasks won’t run.
  • Every 5 minutes is a good default. WooCommerce stores with many scheduled actions may want every minute.

How to test it

Install WP Crontrol or open Tools → Site Health → Info. Events shouldn’t show as overdue after the cron job has had time to run.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only