Using the WordPress Cron (WP-Cron) Utility, this guide will cover managing WP-Cron Events using various WordPress Command Line Interface (WP-CLI) commands.
Overview of Managing WordPress Cron (WP-Cron) Events with the WordPress Command Line Interface (WP-CLI)
How Do You See WordPress Cron (WP-Cron) Events in WordPress?
Once on the WordPress Dashboard, click Tools > Cron Events. You will see a list all of the WP-Cron Events occurring on your WordPress website on multiple rows. Each WP-Cron Event is shown on its own row, with each one having a Delete option available.
WordPress Cron (WP-Cron) works by checking, at the time every page is loaded for the site, a list of scheduled tasks to see which of them needs to be run. Any WP-Cron Event due to run will be called during that page-loading event.
Please note that WP-Cron functionality does not run constantly as the System Cron functionality does. WP-Cron functionality is only triggered in conjunction with page-loading events.
Understanding Unix/Linux System Cron & System Cron Jobs
The term that follow a schedule or run at regular intervals. For example, web servers generally use Cron (also known as System Cron) to manage server maintenance and to schedule tasks. Please be aware that these type of Cron Jobs are managed and run at the Unix/Linux operating system level, and thus are considered System Cron (Cron for short) and System Cron Jobs accordingly.
What are Cron (System Cron), Cron Jobs (System Cron Jobs) & Crontab?
Cron is a task scheduler that lets you execute a script or command automatically on a web server at a future date. It helps you automate repetitive processes. Cron is the Cron Job scheduler on Unix/Linux operating systems. For instance, you can use Cron to send emails at regular intervals automatically. Crontab (derived from Cron Table) is a file which contains the schedule of Cron Job entries to be run and at specified times.
Understanding the WordPress Cron (WP-Cron) Utility
WordPress has its own WordPress Cron (WP-Cron) system and corresponding WP-Cron Events you can use to schedule tasks. This guide will show you how to manage WP-Cron Events using various WordPress Command Line Interface (WP-CLI) commands.
You can schedule tasks a minute to a year in advance using the WordPress Cron Utility called WP-Cron. Here are some scheduled tasks WordPress performs using WP-Cron:
Checking for WordPress core updates
Checking for plugin and theme updates
Cleaning up spam
Publishing a scheduled post
Many WordPress plugins also rely on WP-Cron to manage scheduled tasks — such as creating automatic backups, clearing the cache, etc. Each task is a WP-Cron Event.
Using the WP-CLI)
WP-CLI is the command-line interface for WordPress that lets you update plugins, configure multisite installations, and do more using commands. You can work on your website without opening a web browser or the WP-Admin Dashboard.
You can also create and modify WordPress scheduled tasks (WP-Cron) through the Nexcess Client Portal.
Managing WordPress Cron (WP-Cron) Events with
Here are the WP-Cron commands you can use to schedule new tasks or manage the scheduled tasks.
wp cron event list
This command lists all WP-Cron Events scheduled to run on your WordPress website:
To obtain a list of the scheduled WP-Cron Events in JSON, add --fields=hook,next_run --format=json after the wp cron event list command:
If you manage a multisite, you will need to define a site URL as follows to list the scheduled tasks:
wp cron event run
This command executes the tasks associated with the given hook.
Running All Due WordPress Cron (WP-Cron) Events with WP-CLI
You can use the following WP-CLI command to execute all currently due WP-Cron Events:
You might have to run a WP-Cron Event manually to see if things are working correctly or to troubleshoot certain things. The following command would help you achieve this:
Here is an example of running a scheduled WP-Cron Event manually:
To run all WordPress scheduled events manually, whether they are due or not, you can use the following WP-CLI command:
wp cron event schedule
This command lets you add your WP-Cron Events to your WordPress site. You can configure the WP-Cron event to run hourly, daily, or once a week. You can also set it up as a non-repeating event.
As you add your WP-Cron Events, they will appear in the events list.
Use the following command to schedule a custom WP-Cron Event. The event will be triggered the next time the WP-Cron Utility runs:
Scheduling a Custom Cron Event for a Specific Date/Time
By adding additional parameters like the date and time, you can schedule Cron Events to run at a specific time. In the following example, a new event called “cron_test” is scheduled to run in one hour:
Here are other examples of scheduling a task to run at different times of the day:
>> Run the Event on a Specific Date
>> Run the Event in 1 Week
>> Run the Event Next Wednesday
Schedule Recurring Cron Events
To schedule recurring WP-Cron Events, you need to add a parameter specifying how frequently the event should occur. For instance, you can set a WP-Cron Event to run hourly, daily, weekly, monthly, or even yearly.
This example uses the WP-CLI command to instruct WordPress to run ‘cron_test’ now and rerun once per day:
The default intervals provided by WordPress are hourly, twicedaily, and daily. Check out the Code Reference at WordPress.org for more information.
wp cron event unschedule
This command lets you unschedule an event in WP-Cron:
wp cron event delete
You can also delete a scheduled event using WP-CLI. Run the following command along with the action hook name to delete an existing event:
The following example shows how you can delete all scheduled WP-Cron Events for a given hook, where ‘cron_test’ is the hook here in this example:
WordPress Cron (WP-Cron) & Performance
Most WordPress plugins depend on WP-Cron to schedule backups, site health checks, and cache management. Unfortunately, this can cause performance issues as all plugins try to access a single file.
WP-Cron is often triggered as a user visits your website. So for smaller websites with low traffic, you can rely on WP-Cron without performance issues. But for larger websites, WP-Cron becomes a performance bottleneck and slows down the whole website.
You can improve your website’s performance and reliability of the website’s scheduled tasks and reduce the server load by using an optimized WP-Cron Event Schedule. In Nexcess Managed WordPress Plans, the internal WP-Cron Utility is disabled by default to avoid performance issues.
Nevertheless, if you want to enable the WP-Cron Utility, open your wp-config.php file and change the value of 'true' to 'false' in this line:
However, we do not recommend enabling WP-Cron as it will drastically affect your site performance. If you are unsure how to handle this, please contact our support team by email or .
wp cron test
If you're experiencing issues with scheduled tasks within WordPress, your WP-Cron configuration might be to blame. Run the following command on the WordPress root directory to ensure the WP-Cron system is working properly:
If you have your internal WP-Cron disabled as is the default setting on our Nexces WordPress plans, you will see the following message:
If that’s not the case, you should see this result:
Using this guide, you can schedule your tasks through WP-CLI. As a result, you can automate your recurring tasks and focus on your business instead of worrying about your website.
Do you have any questions?
Useful Links Related to the WordPress Cron (WP-Cron) Utility
Useful Links Related to WordPress Maintenance Mode
Other Useful WordPress Links for Developers & Admins
About the Nexcess Portal
Starting with a new hosting partner can be overwhelming. For that exact reason, we have prepared a Nexcess Portal Guide to make each client’s introduction to our Nexcess Portal easier.
How to Become a Nexcess Portal Pro
You signed up for an account with Nexcess but now what do you do? New systems can be intimidating to learn, so we’ve put together this guide to help explain what is in the portal and where to find it.
Read more about the Fully Managed WordPress Hosting and its benefits for your business.
Build Better Websites with Fully Managed WordPress Hosting
It’s hosting optimized for WordPress. That means a faster, more secure and scalable website. Smart monitoring tools are built-in to help you keep it that way.
It’s why WordPress Users Trust Nexcess Hosting.
We also have a variety of Nexcess support articles about WordPress, including how to get your site going with a number of different configuration options. These resources include a great article on setting this up for Migrating to Nexcess with managed WordPress and managed WooCommerce hosting.
If you need any assistance with the above-mentioned, don't hesitate to reach out. For 24-hour assistance any day of the year, Nexcess customers can contact our support team by email or through your Client Portal.
Resources for More Information
New Customers: Fully Managed Hosting Solutions
- Scope of Support
- Getting started with managed WordPress and WooCommerce hosting
Migrating to Nexcess with managed WordPress and managed WooCommerce hosting
- Going live with your site in Managed WordPress and Managed WooCommerce hosting
- WordPress Cleanup 101: 9 Easy Ways To Clean Up and Optimize Your WordPress Site
- How to configure the Nexcess CDN with WordPress and CDN Enabler
- The Nexcess Plugin Performance Monitor
- Viewing AWStats for Managed WordPress & WooCommerce