⏰ WP-Cron Runs on Page Views — That’s Bad
WP-Cron triggers on visitor traffic. No visitors? Tasks never run. Replace with system cron for reliable scheduling.
🔧 Disable WP-Cron
# Add to wp-config.php
define('DISABLE_WP_CRON', true);
📦 Set Up System Cron
# Every 5 minutes */5 * * * * wget -q -O - https://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1 # Or using curl (more reliable) */5 * * * * curl -s https://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1 # Or using PHP CLI (fastest) */5 * * * * php /path/to/wp-cron.php >/dev/null 2>&1
✅ Creating Custom Cron Events
// Schedule daily backup
if (!wp_next_scheduled('my_daily_backup')) {
wp_schedule_event(time(), 'daily', 'my_daily_backup');
}
add_action('my_daily_backup', 'run_backup');
function run_backup() {
// Export database, backup uploads
}
// Custom intervals
add_filter('cron_schedules', 'add_custom_intervals');
function add_custom_intervals($schedules) {
$schedules['every_30_minutes'] = array(
'interval' => 1800,
'display' => __('Every 30 Minutes')
);
return $schedules;
}
💡 Debug Cron
- Install WP Crontrol plugin to see all scheduled events
- Check if cron is running:
wp cron event list(WP-CLI) - Run cron manually:
wp cron event run --due-now - Log cron output to debug:
> /var/log/wp-cron.log 2>&1
“Site had low traffic. Scheduled backups never ran because WP-Cron needed visitors. Switched to system cron. Now backups run every day at 2 AM reliably.”
