How7o
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Reading: How to Schedule a Cron Job in WordPress Without a Plugin
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > 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.
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

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
Display PHP errors — ini_set + php.ini configuration
How to Display PHP Errors
May 10, 2026
PHP convert string to uppercase — strtoupper and mb_strtoupper
How to Convert a String to Uppercase in PHP
May 10, 2026
PHP string to float conversion with cast, regex cleanup, NumberFormatter
How to Convert a String to Float in PHP
May 10, 2026
PHP merge arrays without duplicates — union operator and array_unique
How to Combine Two Arrays Without Duplicates in PHP
May 10, 2026
PHP delete array element — unset, array_splice, array_filter, array_search
How to Delete an Element from a PHP Array
May 10, 2026

You Might Also Like

Laravel foreign key constraint linking posts.user_id to users.id in a schema diagram
Web Development

How to Add Foreign Keys in Laravel Migration

6 Min Read
Laravel 403 forbidden on shared hosting — root htaccess rewrite into public folder
Web Development

Fix “403 Forbidden” on Laravel Shared Hosting

8 Min Read
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
Laravel left outer join — query builder leftJoin illustration with two tables
Web Development

How to Do a Left Outer Join in Laravel Query Builder

8 Min Read
How7o

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

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?