WordPress
Cron Event Generator
Generate WordPress WP-Cron schedule and event registration code.
Configuration
Generated PHP
// Configure options on the left to generate WP-Cron code
WordPress Cron Event Generator — WP-Cron Explained
WP-Cron is WordPress's built-in pseudo-cron system. Unlike a true server cron job, WP-Cron events only fire when someone visits your site — WordPress checks if any scheduled events are due and runs them during that page load. This tool generates the complete PHP code needed to register, schedule, run, and clean up a recurring WP-Cron event.
How the Generated Code Works
- Custom interval filter (optional) — WordPress ships with
hourly,twicedaily, anddaily. To use a custom interval, register it via thecron_schedulesfilter before scheduling the event. - Activation hook — Uses
register_activation_hook()to schedule the event once when the plugin is activated. Thewp_next_scheduled()check prevents duplicate scheduling if the plugin is deactivated and reactivated. - Callback function — The placeholder function that runs on each scheduled tick. Add your background processing logic here.
- Deactivation hook — Clears the scheduled event when the plugin is deactivated. Failing to do this leaves orphaned cron entries in the database.
WP-Cron Limitations and Alternatives
- WP-Cron events only run when a page is visited. On low-traffic sites, events may fire late or not at all.
- For reliable scheduling on production sites, disable WP-Cron (
define( 'DISABLE_WP_CRON', true );in wp-config.php) and add a real server cron job that hits/wp-cron.php?doing_wp_cronon your desired interval. - Avoid scheduling tasks that take more than a few seconds — they run in-process during a page load and can cause timeouts.
- Use the WP Crontrol plugin to inspect and manually trigger scheduled events during development.
Registering as a Plugin vs Theme
Always register WP-Cron events from a plugin, not a theme. Themes do not have activation/deactivation hooks, which means your scheduled event will never be cleanly deregistered and could run indefinitely even after the theme is changed.