WordPress Cron Jobs: Scheduling Tasks the Right Way

Scheduled tasks power some of WordPress’s most important behavior — publishing posts, checking for updates, sending emails. But WP-Cron has quirks that trip up many developers. Let’s schedule tasks the reliable way.

How WP-Cron Actually Works

Despite the name, WP-Cron isn’t a real system cron. It runs on page loads: when someone visits your site, WordPress checks whether any scheduled tasks are due and runs them. This means on a low-traffic site, scheduled tasks can fire late — or not at all — while on a high-traffic site they can fire too often and add load.

Scheduling a Task

Hook Into a Schedule

WordPress ships with hourly, twice-daily, and daily schedules. You register an event tied to a custom hook, then attach your function to that hook. When the event is due, WordPress fires the hook and your code runs.

Add Custom Intervals

Need every fifteen minutes or every week? You can register custom intervals with a filter, then schedule events against them. Just remember to keep frequent tasks lightweight so they don’t bog down page loads.

The Reliability Problem

Because WP-Cron depends on traffic, it’s unreliable for anything time-sensitive. If your store needs to process orders at exactly midnight, you can’t trust visitor-triggered cron. The fix is to disable WP-Cron’s default behavior and trigger it from a real server cron job instead.

  • Disable internal cron — set the WP-Cron constant to false in wp-config.
  • Add a server cron — call wp-cron.php on a fixed schedule via your host or a command-line task.
  • Result — tasks fire on time regardless of traffic.

Best Practices

Always Unschedule on Deactivation

When a plugin is deactivated, clear its scheduled events. Orphaned cron entries pile up and cause confusing behavior. Hook your cleanup into the deactivation routine.

Keep Tasks Fast and Idempotent

A scheduled task should do its work quickly and safely run more than once without side effects. Heavy jobs should be broken into batches so a single run never times out.

Log Your Cron Activity

Silent failures are the worst kind. Log when tasks run and whether they succeed, so you can spot problems before they snowball.

Final Thoughts

WP-Cron is convenient but trust it only for non-critical tasks. For anything that must run on time, hand scheduling to a real server cron. Keep your tasks fast, clean up after yourself, and log everything. Do that, and scheduled work in WordPress becomes dependable instead of mysterious.

Key Takeaways

  • Focus on fundamentals over trends — consistency beats novelty.
  • Measure before and after every change so you know what worked.
  • Make focused, one-at-a-time improvements you can verify and reverse.
  • Turn your process into a repeatable checklist for every project.

Frequently Asked Questions

Is WP-Cron a real cron job?

No. WP-Cron runs on page loads, not on a fixed clock. On low-traffic sites tasks can fire late, which is why critical jobs should use a real server cron.

How do I make scheduled tasks reliable?

Disable WP-Cron’s default behavior and trigger wp-cron.php from a real server cron on a fixed schedule, so tasks run on time regardless of traffic.

Why do my scheduled tasks run twice?

Often from orphaned events left by plugins. Always unschedule events on deactivation and keep tasks idempotent so running twice causes no harm.