June 17, 2024

Cron is a Unix/Linux utility that is typically used to schedule commands or a script on a web server that runs in the background. A cron job is the task itself, which is used to schedule tasks at periodic fixed times, dates, or intervals. Typically these involve repetitive tasks that are automated to save time. In WordPress, this is handled by WP-Cron, which is used to simulate a system cron.

Some examples of a WordPress cron job might involve scheduling a post to publish or a backup plugin running on a predefined schedule. Today we are going to dive into how to easily create, modify, and run a WordPress cron job.

How To Set up a Cron Job In WordPress

It is important to note that WP-Cron is slightly different than a system cron and they each have their own pros and cons. For example, WP-Cron relies entirely on intervals, whereas a system cron relies on specific times. A WP-Cron also only works when the page is loaded (back-end or front-end), which could be less reliable. The default intervals provided by WordPress are hourly, twice daily, and daily.

To schedule WP-Cron events you have to create custom hooks. We recommend checking out the official WordPress plugin handbook which has an amazing guide on scheduling WP Cron events. If you are looking for an alternative way to set up a system cron with WordPress we recommend checking out Tom Mcfarlin’s article on defining a WordPress cron job. And for those who perhaps aren’t as advanced, we are going to explore how to easily use WP-Cron along with the popular free WP Crontrol plugin. This lets you view and control what’s happening in the WP-Cron system.

WP Crontrol

WP Crontrol has over 200,000 active installs with an impressive 4.5 out of 5 rating. Many people in the WordPress community really love this plugin.

This plugin is super useful. Shows what CRON jobs should run, excellent first step in understanding what’s going on and if it’s working or not. 5 Stars right there. Also, you can create new cron jobs and trigger existing ones to run, 5 bonus stars on top. — Josh, creator of Caldera Forms

You can download it from the WordPress repository or by searching for it within your WordPress dashboard under “Add New” plugins. Features of WP Control include:

  • Ability to view all cron events along with their arguments, recurrence, and next run time.
  • Edit, delete, and immediately run any cron events.
  • Add new cron events.
  • Add, edit, and remove custom cron schedules.

Server Cron

If you’re a Kinsta client, we also have a server cron job that runs on all sites every 15 minutes. Check out our article on how to manage server crons at Kinsta.

Leave a Reply

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