This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Try the fastest hosting platform with pay-as-you-go pricing & 24/7 expert support! MIGRATE NOW →

How to Set Up & Manage WordPress Cron Jobs

Updated on March 4, 2024

11 Min Read
wordpress cron job

Many WordPress developers, especially beginners, have common questions, “what is WordPress cron” and “how to manage WordPress cron jobs?” The answer is simple!

Cron is a standard UNIX utility for scheduling task execution (script or command) at a specific time, date, or interval. The task it will execute is known as a cron job. As you can guess, the purpose of a cron job is to automate repetitive tasks so that you can use your time more productively.

However, the WordPress cron job is slightly different from the standard cron, so before diving into action and process, you need to understand what a WordPress cron is and how it works for task automation.

What Is a WordPress Cron Job?

WordPress has its own cron system for scheduling tasks such as checking for updates, scheduling a post for publication, and deleting comments from the trash. All cron jobs are handled by WP-Cron.

While the name (and the main idea) comes from UNIX cron, WordPress cron doesn’t work like that and uses intervals for task scheduling. The default time intervals provided by WordPress are hourly, twice daily, daily, and weekly. Here, the time-based tasks depend on users visiting your site, meaning that WordPress cron will only execute if a user visits your website.

In other words, WordPress cron is executed when the page loads up. Sometimes this isn’t that reliable, and that’s why many users prefer a server-level cron job over the WP-Cron job.

Benefits of Using WordPress Cron

If you want to automate a website process or need to check, verify, and control it regularly, cron jobs come in handy. For example, we might want to ping a server once a day, check the status of a system every hour (and log it into the database), and so on.

WP Cron makes it easy for the WordPress core and other plugins to perform time-based tasks. It is relatively easy to set up a WordPress Cron job instead of using a real cron job that requires knowledge of Linux commands.

Also, because the WP-Cron uses intervals to schedule tasks, you can rest assured that your task will eventually run even if the scheduled time elapses, unlike a real cron that specifies the exact time a task should run. If the time passes and the task fails to run, then it will not run again until you manually reschedule it.

Optimizing Cron Jobs Made Easier With Cloudways

Our WordPress hosting’s built-in Cron Optimizer automates tasks, delivering smooth and reliable site performance.

How to Manage WordPress Cron Jobs – 2 Methods

There are many ways to set up and manage WordPress cron jobs, but I’ll show you two popular methods. You can use any of these when using our managed WordPress hosting.

The first uses a cron management plugin like WP Crontrol that allows you to add, modify, and manage WordPress cron jobs directly from the WP dashboard. You can also create a cron job, build hooks and functions, and define custom time intervals for tasks.

And the second method is with WordPress CLI.

How to Manage WordPress Cron Jobs With Plugins

I’ll use the WP Crontrol plugin that allows you to view and control WordPress cron for your WordPress application. It is the popular plugin that handles WP cron jobs and has more than 200,000+ active installations.

WP-Cron does not run continuously. By default, the wp-cron.php fires on each page load, which on high-traffic websites can cause issues. If a website doesn’t have sufficient PHP workers, sometimes a request will come in, and WordPress will produce the cron, but the cron must hold up for the worker, and so fair sits there.

This is the easiest method of managing WordPress cron jobs, and you can quickly view, edit, create, delete, and do much more with WordPress cron events.

So let’s get started!

Step 1: Install the WP Control Plugin

Just like any other plugin, you need to install WP Crontrol from the plugin repository and activate it.

WP-Control-Plugin

Once it’s installed, you’ll notice that a new option, “Cron Events” has appeared in the Tools tab.

Cron Events

Step 2: View and Understand Cron Events

Next, you need to click Cron Events and see a list of cron events running on your WordPress application.

Cron-Events-List

You can run, edit, and delete your cron events from this section. You’ll see this option when you hover your mouse over any cron event.

You’ll also find useful information about these cron jobs and quickly identify which cron job is used for what purpose and much more.

  • In the first column, Hook shows the name of the hook used by the WordPress core or any plugin. For instance, the prefix “wp” simply shows it’s a cron of WordPress core.
  • You’ll also notice that there’s no option for deleting these cron events however you can use the edit and run now options. Similarly, for your plugins, you’ll notice other prefixes being used (for instance, for WooCommerce, “wc” or “woocommerce”).
  • The second column, Arguments, just contains the arguments passed to the hook functions.
  • The third column shows when this cron job will run next time.
  • The fourth column, Action, shows what action this cron will perform (the “function” of the cron job).
  • The last column defines the recurrence timings of the cron jobs. This is the time interval for the scheduled task.

No More Site Management Worries with Cloudways Hosting

Migrate to our WordPress hosting for automatic updates, boosted performance, and experience efficient task scheduling with Cron Optimizer.

Step 3: Edit Cron Event

Now let’s edit a WP cron job to test this plugin.

  • Go to a hook’s name and click edit.

Cron-events-edit

  • A new section, “Edit Cron Event” will pop up where you’ll see different fields. In my case, I edited the “wp_privacy_delete_old_export_files” hook.
  • Next, I’m going to change the recurrence of this cron job to ‘Once Hourly (hourly)’.

Edit-Cron-Events

Step 4: Adding a Custom Time Interval

Next, I’ll show you how to add a custom time interval for your cron events.

  • Go to WordPress Settings → Cron Schedules.
  • Now, click on the “Cron Schedule” tab, and a new screen will appear where you’ll see the details of the scheduled time intervals.
  • Fill in the fields Internal Name, Interval Seconds, and Display name, and then click Add Cron Schedule.

Cron-Schedule

  • Note that the input for the interval is in seconds. I will use 600 seconds to set the interval to 10 minutes.
  • You can now edit your cron event and replace it with your custom interval.

Edit-Cron-Events-2

Step 5: Adding a New Cron Event

Now you know how to manage the simple tasks for your cron events but what if you want to add your own cron job for your WordPress application? Don’t worry; it’s so simple, and you must follow the instructions below.

  • First, click Add Cron Event, and you’ll get into the add cron section.
  • Then, just give a hook name as you wish (should follow normal PHP naming convention and no spaces).
  • Then, add arguments (it’s optional); in my case, it’s blank.
  • Next, select any option, and put a time in the Next Run field.
  • Last, choose a recurrence time (schedule time) for your new cron and click Add Event.

Add-Cron-Events

  • If you have any queries regarding this, you can check any running cron job settings from your cron events.
  • After adding a new cron job then, go to the cron events tab and check your newly created cron. You’ll notice that the action column will show you None (error). This is because you haven’t defined any actions for this cron job.
  • Therefore you need to write a few lines of code in the functions.php file of the theme and add an action.

Cron Events List 2

Note: Before going any further, it’s highly recommended to back up the WordPress site.

  • Go to WordPress Dashboard → Appearance, and click on the Theme File Editor.
  • Click on the function.php file from the Theme Files option on the right side of the page.
  • Add the following lines of code right after <?php into your theme’s function.php file
add_action( 'cloudways_new_cron', 'cw_function' );
function cw_function() {
wp_mail( '[email protected]', 'Cloudways Cron', 'Cloudways - a Managed Cloud Hosting!' );
}

Note: Don’t forget to replace my email address with your own.

Adding-code-in-fnction-php-file

You can see in the above image I directly edited it with the WordPress dashboard. If you wish, you can edit this file via an FTP client like FileZilla.

Next, check the email inbox and see whether we’re receiving the message.

Gmail cron job email

Tada! It’s done, and we’ve successfully added a new cron event.

How to Manage WordPress Cron Jobs With WP CLI

You can also view and manage all your WordPress cron jobs from WordPress CLI. At Cloudways, you must launch the terminal and log in with the server credentials.

  • You can use PuTTy to log in to your server. Enter the IP address of your server, and click Open.

PuTTY-login

  • Enter the username and password of your server in PuTTy from the Cloudways server management panel.

master credentials

  • Next, place the path of your WordPress application. In my case, the URL was :
cd applications/urrghmpqks/public_html/

WP-CLI-Change-Directory-command

  • Next, you need to run this command:
wp cron event list

wp-cron-event-list

  • You can see the hook name, next run time, next run relative, and recurrence (scheduled time).

How to Set Up a Real Cron Job

Now, you know what WordPress cron job is and how it works. What if you want to replace it with a real cron job for low traffic, important tasks that need to be run at a particular time, excessive DDoS attacks, or high page load time?

So let’s get started!

Step 1: Open and Edit wp-config.php File

First, you need to open the wp-config file using an FTP client like FileZilla or SSH client such as PuTTY. After that, edit the file and place the following line of code before the line where it says /* That’s all. Stop editing! Happy blogging. */

define('DISABLE_WP_CRON', true);

WP Config file cron job

This code disables the running cron events on your WordPress site, and now you can create a real cron job.

Step 2: Adding a New Cron Job to Server

Next, log in to your Cloudways platform, then go to Application Management panel → Cron Job Management → Advanced section.

Then add the following command and click Save Changes:

*/5 * * * * wget -q -O - 'https://wordpress-413270-1299955.cloudwaysapps.com/wp-cron.php?doing_wp_cron' >/dev/null 2>&1

cron job management

In the above command, first, I defined an interval of five minutes for the cron job. You can use this site to check the time schedule expression. In my case, */5 * * * *is the interval expression.

That’s all! You’ve successfully added a real cron job.

Experience Hands-off Hosting with Cloudways Autonomous

Autonomous scales your site to meet growing demands without manual intervention, eliminating downtime concerns & giving you a fully managed hosting experience.

How to View and Control WordPress Cron Jobs

To optimize the performance of your WordPress site, it’s essential to efficiently view and control cron events. Follow these steps using the WP Crontrol plugin:

  • Installation and Activation:
    • Begin by installing and activating the WP Crontrol plugin on your WordPress site.

wp crontrol plugin

  • Accessing Cron Events:
    • After activation, navigate to the Tools » Cron Events page to view and control cron settings.

wordpress tools section cron events

  • Viewing Cron Events:
    • The page displays a list of all scheduled cron events on your site, identified by hook names.
    • Hook names often give insights into the purpose of each event.
    • Information includes the next scheduled run and the time interval between occurrences.

cron event schedule

  • Controlling Cron Events:
    • In the list, under certian plugins, you’ll see options to Edit | Run now | Pause this hook | Delete.
    • Caution: Exercise care when dealing with cron events, especially default WordPress ones.

cron control option within WP crontrol plugin

  • Handling Resource-Intensive Events:
    • If a plugin creates a resource-intensive cron event, first check the plugin settings for control options.
    • If none, click on the ‘Edit’ link next to the cron event for further adjustments. I’ll tweak the breeze_purge_cache plugin settings for this example.

editing cron settings in wp crontrol plugin

  • Modifying Cron Settings:
    • Clicking ‘Edit’ opens the ‘Modify Cron Event’ tab, where you can change the frequency of the event.
    • Once modifications are done, click ‘Update Event’ to save your settings.

Summary

I hope this article helped you understand how the WordPress cron job works. I’ve discussed two methods to manage WordPress cron jobs; one through a plugin and the other through WP-CLI. I’ve also discussed setting up a real cron job on a WordPress live server. Please let me know in the comment section below if you have any questions.

Frequently Asked Questions

Q: How do I run a cron job in WordPress?

A: There are three ways to run the cron jobs in WordPress.

  1. First, you can use the WP Control plugin.
  2. Second, you can use WP CLI commands.
  3. Third, you can run cron jobs from the Cloudways Platform (if you are a Cloudways customer).

Q: Where are WordPress cron jobs stored?

A: Cron jobs are stored in the wp_options table of the WordPress database where the option_name is cron. You can run the following SQL command to see the cron data.

select * from wp_options where option_name = 'cron'

Q: What is WP Cron Control?

A: WP Cron control is a WordPress plugin that lets you view and control what’s happening in the WP-Cron system.

Q: How can I create and manage cron jobs in WordPress?

A: You can manage WordPress cron jobs using PHP code or the WP Crontrol plugin. This plugin lets you oversee cron events, edit their timings, and add new jobs from your admin dashboard.

Q: Can I schedule a specific time for a WordPress cron job to run?

A: Yes, you can set a specific time for WordPress cron jobs with the wp_schedule_single_event() function. This function lets you set a Unix timestamp for the task execution.

Q: Are there any plugins or tools available to help with WordPress cron job management?

A: Several plugins, such as WP Crontrol, Advanced Cron Manager, WP-Cron Status Checker, and WooCommerce Scheduled Actions Manager, can help manage WordPress cron jobs.

Q: What happens if a WordPress cron job fails to execute?

A: Failure of a WordPress cron job can lead to missed post-publication times, delayed updates, inadequate maintenance, and backup issues.

Q: How do I create a cron job in WordPress without plugins?

A: You can set up a cron job by either adding custom code to your theme’s functions.php file, using a custom plugin, or scheduling cron jobs directly on your server’s control panel or via a command-line interface like SSH. Ensure to replace “yoursite.com” with your actual domain.

Q: How do I see all cron jobs in WordPress?

A: Navigate to the WordPress Dashboard, click on Tools > Cron Events. Here, you’ll find a list of all WP-Cron Events happening on your website, each displayed on a separate row. Additionally, each event row provides a Delete option for management.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Mansoor Ahmed Khan

Been in content marketing since 2014, and I still get a kick out of creating stories that resonate with the target audience and drive results. At Cloudways by DigitalOcean (a leading cloud hosting company, btw!), I lead a dream team of content creators. Together, we brainstorm, write, and churn out awesome content across all the channels: blogs, social media, emails, you name it! You can reach out to me at [email protected].

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now