How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Schedule a Cron Job in WordPress Without a Plugin
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Schedule a Cron Job in WordPress Without a Plugin
Web Development

How to Schedule a Cron Job in WordPress Without a Plugin

how7o
By how7o
Last updated: May 10, 2026
7 Min Read
WordPress cron job without a plugin — cron_schedules, wp_schedule_event, and action callback
SHARE

A wordpress cron job no plugin setup is three pieces of code in functions.php: a custom interval (optional), a wp_schedule_event call guarded by wp_next_scheduled, and an add_action for your event hook. WordPress’s WP-Cron API handles the scheduling; you just tell it what to run and when. This guide covers the full pattern, how to clear stale events, and why you’ll probably also want to pair it with a real system cron — covered in the companion guide.

Contents
  • TL;DR
  • Step 1 — Custom interval (optional)
  • Step 2 — Register the recurring event
  • Step 3 — The callback
  • Clearing and inspecting
  • The low-traffic caveat
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-04-23 on WordPress 6.5 and PHP 8.3. Originally published 2024-02-23, rewritten and updated 2026-04-23.

TL;DR

// 1. Custom interval (skip if 'hourly'/'daily'/'weekly' fits)
add_filter( 'cron_schedules', function ( $schedules ) {
    $schedules['every_15_min'] = array(
        'interval' => 15 * 60,
        'display'  => __( 'Every 15 Minutes', 'how7o' ),
    );
    return $schedules;
} );

// 2. Register the event (only if not already scheduled)
add_action( 'init', function () {
    if ( ! wp_next_scheduled( 'how7o_cron_event' ) ) {
        wp_schedule_event( time(), 'every_15_min', 'how7o_cron_event' );
    }
} );

// 3. The callback that runs
add_action( 'how7o_cron_event', 'how7o_run_cron_job' );
function how7o_run_cron_job() {
    // Do something here — update prices, send digest, etc.
}

Step 1 — Custom interval (optional)

function how7o_cron_intervals( $schedules ) {
    $schedules['1hr_cron'] = array(
        'interval' => 3600,                  // in seconds
        'display'  => __( '1hr Interval', 'how7o' ),
    );
    return $schedules;
}
add_filter( 'cron_schedules', 'how7o_cron_intervals' );

Skip this if one of WordPress’s built-in intervals fits — hourly, twicedaily, daily, weekly. Define a custom interval only when you need something the built-ins don’t cover. The interval is in seconds; display is what shows up in plugins that list cron events.

Step 2 — Register the recurring event

function how7o_register_cron_event() {
    if ( ! wp_next_scheduled( 'how7o_cron_event' ) ) {
        wp_schedule_event( time(), '1hr_cron', 'how7o_cron_event' );
    }
}
add_action( 'init', 'how7o_register_cron_event' );

Three parts:

  • wp_next_scheduled('how7o_cron_event') returns the timestamp of the next scheduled run, or false if none. The guard means we only schedule if it’s not already scheduled.
  • time() is the first run timestamp — “start from now.”
  • '1hr_cron' (or whichever interval slug) is how often it repeats.
  • 'how7o_cron_event' is the action hook WordPress fires on each run.
wordpress cron job no plugin — cron_schedules filter + wp_schedule_event + action callback

Step 3 — The callback

function how7o_run_cron_job() {
    // Your actual work: update data, call an API, send emails.
    // Keep this fast — long-running cron can time out.
}
add_action( 'how7o_cron_event', 'how7o_run_cron_job' );

The hook name you registered in step 2 (how7o_cron_event) is what WordPress fires on each run — attach your function to that. Keep the callback fast. If the work is heavy (scanning thousands of posts, calling an external API per post), queue an Action Scheduler or batch-mode job from the cron callback rather than doing it all inline.

Clearing and inspecting

// Remove every queued instance of the event
wp_clear_scheduled_hook( 'how7o_cron_event' );

// Inspect everything currently in the cron queue
$cron = get_option( 'cron' );
var_dump( $cron );

Useful during development. Always run wp_clear_scheduled_hook before switching from one interval to another — otherwise both the old and new schedule coexist. On deactivation of a plugin that registered the event, call wp_clear_scheduled_hook in the deactivation hook so the queue doesn’t accumulate orphan events.

The low-traffic caveat

WP-Cron runs on-page-load: every request checks if any cron event is due and fires them in-process. On a high-traffic site this is fine — there’s always a visitor to trigger it. On a low-traffic site, a cron scheduled for 2am may not fire until someone visits at 9am. For time-sensitive work, disable WP-Cron and hit wp-cron.php from a real system cron — walkthrough in How to Set Up a System-Based Cron Job in WordPress.

Frequently asked questions

What’s the shortest wordpress cron job no plugin setup?

Two hooks: wp_schedule_event to register the recurring event (inside an init callback, guarded by wp_next_scheduled so it only registers once), and a separate add_action for the event’s hook name that runs your actual function. Optionally a cron_schedules filter for custom intervals. That’s it — no plugin needed.

Why wrap wp_schedule_event in wp_next_scheduled?

wp_schedule_event registers the event every time it’s called, which fires on init on every request. Without the guard you’d queue thousands of duplicate events. wp_next_scheduled('your_hook') returns the timestamp of the next scheduled run, or false if none. Registering only when it’s false keeps the queue clean.

What are the built-in intervals?

WordPress ships hourly, twicedaily, daily, and weekly. To run more or less often, define a custom interval via the cron_schedules filter: return an array with your slug (e.g. '1hr_cron') mapping to ['interval' => 3600, 'display' => '1 Hour']. The interval is in seconds.

How do I clear a scheduled event I no longer want?

wp_clear_scheduled_hook('your_hook_name') removes every queued instance of that hook. Run it from a WP-CLI wp eval call or temporarily add it to functions.php, hit any page to fire init, then remove the line. For one-off dumps of the current queue, get_option('cron') returns the raw array.

Does wp-cron actually run on schedule?

No — WordPress’s built-in wp-cron.php only fires when someone visits the site. On low-traffic sites scheduled events can miss their window by hours. The fix is a real system cron job that hits wp-cron.php at a predictable interval — see how to set up a system-based cron job in WordPress.

Related guides

  • How to Set Up a System-Based Cron Job in WordPress — the “make wp-cron actually run on time” follow-up.
  • How to Apply pre_get_posts on Custom Post Types in WordPress — another hook-driven customization.
  • How to Show Custom Notifications in the WordPress Dashboard — a simple admin UI for your cron’s output.
  • How to Deregister or Remove a CSS File in WordPress — sibling priority-matters hook pattern.

References

WordPress developer reference for wp_schedule_event and cron_schedules: developer.wordpress.org/reference/functions/wp_schedule_event.

TAGGED:cronphpwordpress

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article WordPress default posts per page — get_option reads the Settings Reading value How to Get the Default Posts Per Page Value in WordPress
Next Article WordPress system cron — DISABLE_WP_CRON + system crontab hitting wp-cron.php How to Set Up a System-Based Cron Job in WordPress
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Laravel Eloquent ORM — a model class mapping to a database table with query methods
Laravel Eloquent ORM: The Complete Guide to Querying Your Database
June 16, 2026
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
How to Set vi (Vim) as the Default Editor in Ubuntu
June 8, 2026
rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder
rsync Says “ALL DONE” but Files Are Missing: How to Verify
June 8, 2026
Migrate a website to a new server with rsync — files copying from an old server to a new one over SSH
How to Migrate a Website to a New Server With rsync
June 8, 2026
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026

You Might Also Like

Login to Laravel programmatically without a password (Auth::login and loginUsingId)
Web Development

Login to Laravel Programmatically Without a Password (Auth::login & loginUsingId)

4 Min Read
WordPress check if user is logged in with is_user_logged_in()
Web Development

How to Check If a User Is Logged In in WordPress

7 Min Read
Upload files via Ajax with jQuery using FormData
Web Development

How to Upload Files via Ajax with jQuery

4 Min Read
fail2ban shield blocking incoming brute-force probes, log file feeding the scanner
Server Management

How to Install fail2ban on Ubuntu (SSH, nginx, and WordPress Filters)

10 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?