DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
VGSources
Blog

How to Set Up and Manage a WordPress Cron Job

A practical guide to WordPress cron jobs: write a safe scheduled hook, inspect and run events with WP-CLI, configure a server scheduler for predictable timing, and remove obsolete or duplicate events.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WordPress cron (WP-Cron) runs scheduled hooks such as publishing posts, sending queued mail, refreshing feeds and executing plugin maintenance. It is triggered by site requests rather than by a continuously running daemon, so a low-traffic site can run tasks late. For predictable execution, schedule the operating system to request wp-cron.php, then set DISABLE_WP_CRON to stop page loads from spawning additional runs. This guide shows how to register events safely, inspect and run them with WP-CLI, move execution to a server scheduler, and remove obsolete events.

What WP-Cron is and why jobs run late

WP-Cron is WordPress’s hook-based scheduling system. A plugin registers a hook, attaches a callback to that hook, and asks WordPress to create an event for a future timestamp. When WordPress receives a request, it checks for due events and attempts to run them. It is not a continuously running process. The WordPress Developer Resources Plugin Handbook specifically warns that this can be a problem when a critical task must run on time.

As an Amazon Associate I earn from qualifying purchases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The distinction matters operationally:

  • On a busy site, a request may arrive close to the scheduled time and the event can start promptly.
  • On a low-traffic site, no request may arrive for minutes or hours, so a task waits even though its scheduled timestamp has passed.
  • Visitor-triggered spawning can add work to normal page requests and is harder to observe than a server scheduler.

WP-Cron records a next-run time, but that timestamp is a target for the next eligible execution, not a guarantee that the callback will begin at that exact second.

Choose the execution model first

Characteristic Visitor-triggered WP-Cron Server-triggered scheduling
Execution trigger A WordPress request causes WordPress to check and spawn due work. Linux/macOS cron or Windows Task Scheduler requests wp-cron.php at an interval you choose.
Timing predictability Variable; depends on incoming traffic and whether spawning succeeds. More predictable because the operating system initiates the request.
Server access No shell access is required for basic operation. Requires access to a server scheduler and a way to request the site’s wp-cron.php.
Duplicate-event risk Repeated plugin initialization can register the same hook more than once unless guarded. Uses the same WordPress event store, so registration safeguards are still required.
Visibility Inspect with WP-CLI or WordPress code. Inspect with WP-CLI and the scheduler’s own logs or status.
Cleanup Unschedule events when a plugin is deactivated or a task is removed. The same WordPress cleanup is required; disabling page spawning does not delete events.

Keep visitor-triggered WP-Cron when occasional timing drift is acceptable and you do not control the server. Use a server scheduler when a job must be checked at a regular cadence, especially on a low-traffic site. WP-CLI improves visibility and control with either model.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Prerequisites and a safe implementation plan

  • A working WordPress installation and a plugin or controlled code path where the schedule can be registered.
  • A uniquely prefixed hook name that will not collide with another plugin.
  • A callback that can safely run more than once and can handle partial failure.
  • WP-CLI access for inspection and manual execution, if available.
  • For server-triggered execution, permission to configure Linux/macOS cron or Windows Task Scheduler.

Do not register a recurring event on every page load. Registration belongs in plugin activation or another controlled initialization path, and it must first check whether the hook is already scheduled.

Register a recurring event in plugin code

1. Create a unique hook and callback

The hook is the contract between the scheduler and your code. Prefix it with your plugin or project name, then attach the callback with add_action().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<?php
add_action( 'bl_cron_hook', 'bl_cron_exec' );

function bl_cron_exec() {
    // Fetch a small batch, perform the work, and record failures.
}

Use a callback that is short enough to avoid monopolizing a request. Break large jobs into batches, record progress, and make the operation idempotent: if the same event is retried, it should not create duplicate records, send duplicate messages or corrupt state.

2. Schedule only when the hook is absent

On activation, call wp_next_scheduled( 'bl_cron_hook' ). A false result means no event is currently registered, so you can create one. If it returns a timestamp, leave the existing event alone.

register_activation_hook( __FILE__, 'bl_activate' );

function bl_activate() {
    if ( ! wp_next_scheduled( 'bl_cron_hook' ) ) {
        wp_schedule_event( time() + 300, 'hourly', 'bl_cron_hook' );
    }
}

The first argument to wp_schedule_event() is the first-run Unix timestamp. The second is a registered recurrence name, such as hourly. The third is the hook that identifies the callback. In this example, the first check is five minutes after activation and subsequent runs use the hourly interval.

3. Attach the callback exactly once

Keep the add_action() registration in the plugin’s normal load path, not inside an activation function. Activation runs once; the callback registration must be available whenever WordPress processes the event.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
add_action( 'bl_cron_hook', 'bl_cron_exec' );

function bl_cron_exec() {
    $items = bl_get_pending_items( 50 );

    foreach ( $items as $item ) {
        bl_process_item( $item );
    }
}

The example intentionally limits each run to a batch. The scheduling APIs do not impose a universal workload-duration limit, so choose a batch size that fits your hosting limits and application behavior.

4. Use a single event for one-off work

For a task that should happen once—such as processing a delayed action—use WordPress’s single-event scheduling API instead of a recurring event. Give the event its own uniquely prefixed hook and still make the callback defensive, because retries or manual runs can occur.

Verify the event with WP-CLI

Run WP-CLI from the WordPress installation directory, or provide the appropriate path and site context for your environment.

Test whether WP-Cron can spawn

wp cron test

wp cron test checks the WP-Cron spawning mechanism. A failure means you should investigate the site’s ability to make the loopback request before treating an individual plugin as the cause.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

List hooks, times and recurrence

wp cron event list --fields=hook,next_run_gmt,recurrence --format=table

This displays each scheduled hook, its next run in GMT and its recurrence data. Look for your prefixed hook, an unexpected number of entries for the same hook, or a next-run time that is far in the past.

Run all currently due events

wp cron event run --due-now

Use this after correcting a scheduling issue or when you need due work processed immediately. Run it during a controlled maintenance window if the site has many due events, because every due callback will execute.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Create a temporary recurring test event

wp cron event schedule cron_test now hourly

The command schedules the cron_test hook to start now and recur hourly. WP-CLI also accepts a Unix timestamp or a textual datetime in place of now, plus optional arguments. Schedule a test only when a callback for that hook exists or when you are deliberately testing event registration; otherwise WordPress will have no useful work to perform.

Delete or unschedule a hook

wp cron event delete cron_test
wp cron event unschedule cron_test

wp cron event delete deletes all events for the specified hook. wp cron event unschedule removes scheduled events for that hook where supported by the installed WP-CLI version. Confirm the result by running the event-list command again. Deleting a test hook does not remove your plugin’s code or any unrelated hook.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Move execution to the server scheduler

The WordPress handbook recommends an operating-system scheduler when visitor-triggered execution is too irregular. The scheduler should request the site’s wp-cron.php at the cadence you need; WordPress then executes events that are due.

Linux or macOS cron

  1. Confirm the site URL and the location of the scheduler account that should make the request.
  2. Open that account’s crontab with crontab -e.
  3. Add a line at the desired interval. For a five-minute check, an example is:
    */5 * * * * wget -q -O - 'https://example.com/wp-cron.php?doing_wp_cron=1' >/dev/null 2>&1

    Replace https://example.com with your own site address. The command requests the endpoint and discards normal output; retain or redirect output differently if you need scheduler logs.

  4. Save the crontab, then verify the request and the WordPress event list. A scheduler interval is a check frequency, not a promise that every callback completes within that interval.

Use the HTTPS address that resolves to the site and ensure the server can reach it. If your host supplies a control-panel cron interface instead of shell access, enter the same request and interval there.

Windows Task Scheduler

  1. Create a basic task in Task Scheduler and choose the account that is allowed to run it.
  2. Set a trigger for the required repeat interval.
  3. Configure an action that requests the site’s wp-cron.php, using the HTTP client available on that server.
  4. Run the task manually once, then confirm with wp cron event list or the task’s history that the request succeeds.

Windows Task Scheduler controls when the endpoint is requested; WordPress still decides which events are due and invokes their callbacks.

Disable page-triggered spawning after the switch

Once the server scheduler is working, add this constant to wp-config.php before the line that says WordPress is all done editing the file:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
define( 'DISABLE_WP_CRON', true );

Without this setting, normal page loads continue trying to spawn WP-Cron, causing unnecessary requests and potentially competing with the server-triggered run. Disabling it does not delete schedules; it only stops the page-load trigger. Keep the external scheduler active or due events will stop being processed automatically.

Remove schedules when a plugin or feature is retired

WordPress can continue attempting obsolete tasks after a plugin is deactivated or removed unless the events are explicitly unscheduled. Register cleanup in the plugin deactivation hook.

register_deactivation_hook( __FILE__, 'bl_deactivate' );

function bl_deactivate() {
    $timestamp = wp_next_scheduled( 'bl_cron_hook' );

    if ( $timestamp ) {
        wp_unschedule_event( $timestamp, 'bl_cron_hook' );
    }
}

wp_next_scheduled() returns the next timestamp for the hook. Pass that timestamp and the hook to wp_unschedule_event(). If your implementation can create more than one event for the same hook, repeat the lookup-and-unschedule operation until no timestamp remains, or use an administrative cleanup method that removes every instance. Verify afterward with wp cron event list.

Prevent duplicate cron events

Duplicates usually come from registration code that runs repeatedly without checking the existing schedule. Symptoms include several rows for the same hook, a callback firing multiple times per interval, repeated emails or repeated API requests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Use a unique, project-prefixed hook name.
  • Call wp_next_scheduled() before every recurring registration path.
  • Prefer activation or a deliberate migration step over registering from an ordinary page request.
  • Make the callback idempotent so a retry cannot duplicate its side effects.
  • Inspect with wp cron event list --fields=hook,next_run_gmt,recurrence --format=table after deployments and migrations.
  • Remove obsolete copies with WP-CLI before creating a corrected schedule.

Do not solve a duplicate by merely shortening the interval. First determine how many events exist and which code path created them.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot late, missing or repeated jobs

The event is late on a quiet site

This is expected behavior for visitor-triggered WP-Cron: no request means no spawn attempt. Run wp cron event list to confirm that the next-run time is in the past, then move execution to a server scheduler and set DISABLE_WP_CRON.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

WP-Cron spawning fails

Run wp cron test. If it reports a failure, verify that the site can receive its own request and that the configured URL is reachable from the server. Fix the loopback or scheduler request before changing plugin intervals.

The hook does not appear

Confirm that the plugin activation path ran, that the hook name in wp_schedule_event() exactly matches the hook passed to add_action(), and that the event-list command is pointed at the intended WordPress installation. Reactivating a plugin should not create a second event if the guard is present.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The callback runs more than once

List events and count rows for the hook. If multiple rows exist, delete or unschedule the extras, then correct the registration path. Also check whether an external scheduler and page-triggered WP-Cron are both active; that combination is unnecessary after a successful migration, even though WordPress’s own locking normally coordinates individual runs.

Due events remain after a plugin was removed

Deactivation cleanup may not have been registered in an older version, or the plugin may have been deleted without deactivation. Remove the obsolete hook with WP-CLI, then verify that it no longer appears in the event list. Do not delete a hook until you have confirmed it belongs to the retired feature.

A run fails partway through

Keep callbacks small, process bounded batches and record enough state to resume safely. A callback should tolerate a retry and should not assume that every item or remote operation succeeds. The scheduling layer determines when the callback is attempted; your callback determines whether partial failure can be recovered.

Operational checklist

  1. Give the hook a unique prefix and attach its callback.
  2. Schedule only after wp_next_scheduled() confirms that no event exists.
  3. Choose recurring or single-event scheduling according to the job’s purpose.
  4. Use a short, batched, idempotent callback with defensive failure handling.
  5. Run wp cron test and inspect the event with the WP-CLI list command.
  6. For precise timing, configure Linux/macOS cron or Windows Task Scheduler to request wp-cron.php.
  7. After the external scheduler is verified, define DISABLE_WP_CRON in wp-config.php.
  8. Unschedule retired hooks during plugin deactivation and remove orphaned events manually when necessary.

The practical rule is simple: WP-Cron is convenient because it is integrated into WordPress, but it is request-driven. Guard registration to prevent duplicates, use WP-CLI to see what is actually scheduled, and hand execution to the server scheduler when lateness is unacceptable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.